Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL texture inverted
    primarykey
    data
    text
    <p>I'm trying to map the input from my webcam to a plane in OpenGL. I'm using OpenCV to get the images from the webcam. </p> <p>The problem I have is that the texture is vertically inverted, if my texture is "v", the current result is "^". </p> <p>I want to fit the image taken from the webcam to my plane (2x2). Its lower left corner is -1, -1 and the upper right corner is 1,1. </p> <p>The code is: </p> <pre><code>const int VIEWPORT_WIDTH = 640; const int VIEWPORT_HEIGHT = 480; const int KEY_ESCAPE = 27; CvCapture* g_Capture; IplImage* image; GLint g_hWindow; GLvoid InitGL(); GLvoid OnDisplay(); GLvoid OnReshape(GLint w, GLint h); GLvoid OnKeyPress (unsigned char key, GLint x, GLint y); int main(int argc, char* argv[]) { glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowPosition(100, 100); glutInitWindowSize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); g_hWindow = glutCreateWindow("Image"); image = cvLoadImage("average.jpg", 1); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image-&gt;width, image-&gt;height, GL_RGB, GL_UNSIGNED_BYTE, image-&gt;imageData); InitGL(); glutMainLoop(); return 0; } GLvoid InitGL() { glClearColor (0.0, 0.0, 0.0, 0.0); glutDisplayFunc(OnDisplay); glutReshapeFunc(OnReshape); glutKeyboardFunc(OnKeyPress); } GLvoid OnDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(0.0f, 0.0f, -2.5f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); glPopMatrix(); glutSwapBuffers(); } GLvoid OnReshape(GLint width, GLint height) { if (height==0) height=1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, width, height); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 1.0f, 10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( 0.0, 0.0, 0.0, 0.0, 0.0, -6.0, 0.0f, 1.0f, 0.0f); } GLvoid OnKeyPress(unsigned char key, int x, int y) { switch (key) { case KEY_ESCAPE: cvReleaseImage(&amp;image); glutDestroyWindow(g_hWindow); exit(0); break; } glutPostRedisplay(); } </code></pre> <p>BTW. In this code I'm loading an image instead of getting from the webcam.</p> <p>Any suggestion?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload