void VideoViewer::display(GLContextData& contextData) const
{
    /* Get the context data item: */
    DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);

    /* Set up OpenGL state: */
    glPushAttrib(GL_ENABLE_BIT|GL_TEXTURE_BIT);
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

    /* Bind the texture object: */
    glBindTexture(GL_TEXTURE_2D,dataItem->videoTextureId);

    /* Check if the cached texture is outdated: */
    if(dataItem->videoTextureVersion!=videoFrameVersion)
    {
        /* Upload the most recent texture image: */
        videoFrames.getLockedValue().glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,!dataItem->haveNpotdt);
        dataItem->videoTextureVersion=videoFrameVersion;
    }

    glBegin(GL_QUADS);
    glTexCoord2f(dataItem->texMin[0],dataItem->texMin[1]);
    glVertex2i(0,0);
    glTexCoord2f(dataItem->texMax[0],dataItem->texMin[1]);
    glVertex2i(videoFormat.size[0],0);
    glTexCoord2f(dataItem->texMax[0],dataItem->texMax[1]);
    glVertex2i(videoFormat.size[0],videoFormat.size[1]);
    glTexCoord2f(dataItem->texMin[0],dataItem->texMax[1]);
    glVertex2i(0,videoFormat.size[1]);
    glEnd();

    /* Protect the texture object: */
    glBindTexture(GL_TEXTURE_2D,0);

    /* Draw the video's backside: */
    glDisable(GL_TEXTURE_2D);
    glMaterial(GLMaterialEnums::FRONT,GLMaterial(GLMaterial::Color(0.7f,0.7f,0.7f)));

    glBegin(GL_QUADS);
    glNormal3f(0.0f,0.0f,-1.0f);
    glVertex2i(0,0);
    glVertex2i(0,videoFormat.size[1]);
    glVertex2i(videoFormat.size[0],videoFormat.size[1]);
    glVertex2i(videoFormat.size[0],0);
    glEnd();

    /* Restore OpenGL state: */
    glPopAttrib();
}
void VideoViewer::initContext(GLContextData& contextData) const
{
    DataItem* dataItem=new DataItem;
    contextData.addDataItem(this,dataItem);

    /* Check whether non-power-of-two-dimension textures are supported: */
    dataItem->haveNpotdt=GLARBTextureNonPowerOfTwo::isSupported();
    if(dataItem->haveNpotdt)
        GLARBTextureNonPowerOfTwo::initExtension();

    /* Calculate the texture coordinate rectangle: */
    unsigned int texSize[2];
    if(dataItem->haveNpotdt)
    {
        for(int i=0; i<2; ++i)
            texSize[i]=videoFormat.size[i];
    }
    else
    {
        /* Find the next larger power-of-two texture size: */
        for(int i=0; i<2; ++i)
            for(texSize[i]=1U; texSize[i]<videoFormat.size[i]; texSize[i]<<=1)
                ;
    }

    /* Calculate texture coordinates to map the (padded) texture onto the geometry: */
    for(int i=0; i<2; ++i)
    {
        dataItem->texMin[i]=0.0f;
        dataItem->texMax[i]=GLfloat(videoFormat.size[i])/GLfloat(texSize[i]);
    }

    /* Bind the texture object: */
    glBindTexture(GL_TEXTURE_2D,dataItem->videoTextureId);

    /* Initialize basic texture settings: */
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

    /* Upload the initial texture image: */
    videoFrames.getLockedValue().glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,!dataItem->haveNpotdt);
    dataItem->videoTextureVersion=videoFrameVersion;

    /* Protect the texture object: */
    glBindTexture(GL_TEXTURE_2D,0);
}
Exemple #3
0
void IMUTest::display(GLContextData& contextData) const
	{
	glPushAttrib(GL_ENABLE_BIT);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
	glMaterialSpecular(GLMaterialEnums::FRONT,GLColor<GLfloat,4>(1.0f,1.0f,1.0f));
	glMaterialShininess(GLMaterialEnums::FRONT,25.0f);
	
	/* Draw a global coordinate frame: */
	glPushMatrix();
	glColor3f(1.0f,0.5f,0.5f);
	glRotated(90.0,0.0,1.0,0.0);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,1.0f,0.5f);
	glRotated(-90.0,1.0,0.0,0.0);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,0.5f,1.0f);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	/* Draw a local coordinate frame: */
	glPushMatrix();
	const IMUTracker::State& state=tracker->getLockedState();
	// if(lockPosition)
	// 	glTranslated(5.0,5.0,5.0);
	// else
	// 	glTranslate(state.translation*IMUTracker::Scalar(10));
	glRotate(state.rotation);
	
	glPushMatrix();
	glColor3f(1.0f,0.5f,0.5f);
	glRotated(90.0,0.0,1.0,0.0);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,1.0f,0.5f);
	glRotated(-90.0,1.0,0.0,0.0);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,0.5f,1.0f);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	const IMU::CalibratedSample& sample=samples.getLockedValue();
	
	/* Draw the current linear acceleration vector: */
	glPushMatrix();
	glColor3f(1.0f,1.0f,0.0f);
	GLfloat len=GLfloat(Geometry::mag(sample.accelerometer));
	glRotate(IMUTracker::Rotation::rotateFromTo(IMUTracker::Vector(0,0,1),sample.accelerometer));
	glTranslatef(0.0f,0.0f,len*0.5f);
	glDrawArrow(0.5f,1.0f,1.5f,len,16);
	glPopMatrix();
	
	/* Draw the current magnetic flux density vector: */
	glPushMatrix();
	glColor3f(1.0f,0.0f,1.0f);
	len=GLfloat(Geometry::mag(sample.magnetometer))*0.2f;
	glRotate(IMUTracker::Rotation::rotateFromTo(IMUTracker::Vector(0,0,1),sample.magnetometer));
	// glTranslatef(0.0f,0.0f,len*0.5f);
	glDrawArrow(0.5f,1.0f,1.5f,len*2.0f,16);
	glPopMatrix();
	
	glPopMatrix();
	
	glPopAttrib();
	}