how can i access the camera image in OpenGL ?
in
Core Library Questions
•
1 years ago
I want to make opengl texture image on the camera image.
this is my code.
void drawGraphics( )
{
//cout << endl << "frame #" << frame << endl;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
///*
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img3->width, img3->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img3->imageData );
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
}
glEnd();
//*/
/*
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
gluLookAt(0.0f, 25.0f, 90.0f, 0.0f, 30.1f, 0.0f, 0.0f, 1.0f, 0.0f);
// draw a graphic object
glColor3f(1.0f, 1.0f, 0.0f); // the drawing color "yellow"
glutSolidTeapot( 0.4 );
///*
glEnable(GL_DEPTH_TEST);
for(int i = 0; i < g_3DModel.numOfObjects; i++)
{
if(g_3DModel.pObject.size() <= 0) break;
t3DObject *pObject = &g_3DModel.pObject[i];
if(pObject->bHasTexture) {
glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
}
else
{
glDisable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
}
glBegin(GL_TRIANGLES);
for(int j = 0; j < pObject->numOfFaces; j++)
{
for(int whichVertex = 0; whichVertex < 3; whichVertex++)
{
int index = pObject->pFaces[j].vertIndex[whichVertex];
glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
if(pObject->bHasTexture) {
if(pObject->pTexVerts) {
glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
}
}
else {
if(g_3DModel.pMaterials.size() && pObject->materialID >= 0)
{
glColor3f(g_3DModel.pMaterials[pObject->materialID].fColor[0],
g_3DModel.pMaterials[pObject->materialID].fColor[1],
g_3DModel.pMaterials[pObject->materialID].fColor[2]);
}
}
glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
}
}
glEnd();
}
glDisable(GL_DEPTH_TEST);
*/
//glFlush();
glutSwapBuffers();
frame++;
}
If I write the code like that, the cam image is appear.
and if I remove comment,
only opengl image is seen. the cam image is not appear.
how can i ..
please help me..
1