First off, I will confess I have asked the same question on stackoverflow, but I think this forum might be a better fit.
I am trying to combine 2 things using SDL:
- Draw a webcam feed via an SDL_Surface (from OpenCV).
- Draw some plain colored geometry on top, using OpenGL.
The problem I have is that—I think—the geometry is textured by the screen texture that I draw the webcam feed in, even if I call glDisable(GL_TEXTURE_2D)
right before drawing the quad. See the screenshot below, the square in the top-left is supposed to be white, but it seems to have the color of the bottom-right texel.
The code in my Display
function is as follows:
// screen_surface_ contains a frame from the camera
SDL_UpdateTexture(screen_texture_, NULL, screen_surface_->pixels, screen_surface_->pitch);
SDL_RenderClear(renderer_);
SDL_RenderCopy(renderer_, screen_texture_, NULL, NULL);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 1.0);
glBegin( GL_QUADS );
glVertex3f( 10.0f, 50.0f, 0.0f ); /* Top Left */
glVertex3f( 50.0f, 50.0f, 0.0f ); /* Top Right */
glVertex3f( 50.0f, 10.0f, 0.0f ); /* Bottom Right */
glVertex3f( 10.0f, 10.0f, 0.0f ); /* Bottom Left */
glEnd( );
glColor3f(1.0, 1.0, 1.0);
SDL_RenderPresent(renderer_);
You can view all the code of relevant functions here.
I got a blanket answer saying "Don't mix SDL and OpenGL draw code"; as addressed in this bug report. But that would mean I'm simply stuck waiting for that bug to be fixed, so I'm still looking for a way to disable texturing after SDL_RenderCopy
has been called.
Edit: I've confirmed that it's indeed still using the screen_texture_
. Setting the texCoord
to values between 0-100 shows a part of the webcam feed. (I tried 0-1 first but then I read that texCoords are different for rectangular images).