[SDL] Render targets

Mason Wheeler masonwheeler at yahoo.com
Thu Jul 28 09:55:48 PDT 2011


Your problem is likely that you're in GL_REPLACE mode, which means the
texture color completely overwrites the primitive color. Look here:
http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml for information on
other modes (you "probably" want GL_MODULATE).

On Thu, Jul 14, 2011 at 7:22 AM, Odiee <simula47 at gmail.com> wrote:

> **
> Hi
>
> I have a problem where I can't set the color of the drawing primitive when
> I load some texture before drawing.
> e.g.
> LoadBackTex();
> DrawBack();
> DrawSquare();
>
> where LoadBackTex() loads the *.png image, sets texture format, bind
> texture, calls glTexImage2D with appropriate parameters. (format is GL_RGB)
>
> DrawBack:
>
>
> Code:
>
>
>
>
> void drawBackground(void)
> {
> glBindTexture( GL_TEXTURE_2D, ID_BACK_TEXTURE );
> glBegin( GL_QUADS );
>    glTexCoord2i( 0, 0 );
>    glVertex3f( 0.f, 0.f, 0.0f );
>
>    glTexCoord2i( 1, 0 );
>    glVertex3f( 640, 0, 0.f );
>
>    glTexCoord2i( 1, 1 );
>    glVertex3f( 640, 480.f, 0.f );
>
>    glTexCoord2i( 0, 1 );
>    glVertex3f( 0, 480, 0.f );
> glEnd();
> SDL_GL_SwapBuffers();
> }
>
>
>
>
> DrawSquare:
>
>
> Code:
>
>
>
> void drawSquare(void)
> {
>  glColor3f(1,0,0);
>  glBegin(GL_QUADS);
>        glVertex3f(100, 100, 0.0f);
>       glVertex3f( 150, 100, 0.0f);
>       glVertex3f( 150,150, 0.0f);
>       glVertex3f( 100,150, 0.0f);
> glEnd();
> SDL_GL_SwapBuffers();
> }
>
>
>
>
> The problem is I can't set the color of the square. It draws right, but the
> color remains unchanged.
> It has something with glTexImage2D function because when I disable it, it
> draws fine. I figured it's something with the pixel format but I just can't
> get my finger on it.
>
>
> opengl is initialized with
>
>
> Code:
>
>
>
> void InitGL(void)
> {
> glEnable( GL_TEXTURE_2D );
> glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
> glViewport( 0, 0, 640, 480 );
> glClear( GL_COLOR_BUFFER_BIT );
> glMatrixMode( GL_PROJECTION );
> glLoadIdentity();
> glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
> glMatrixMode( GL_MODELVIEW );
> glLoadIdentity();
> }
>
>
>
>
> and SDL with
>
>
>
> Code:
>
>
>
> int InitSDL(void)
> {
>  if (SDL_Init(SDL_INIT_VIDEO) != 0)
>     {
>      return -1;
>     }
>
>  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
>
>  screen = SDL_SetVideoMode(640,480, bpp, SDL_HWSURFACE  | SDL_OPENGL);
>  if (!screen)
>     {
>      gData->AppendLog("set video mode fail");
>      return -1;
>     }
>
>  return 0;
> }
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110714/27bf3bea/attachment-0008.htm>


More information about the SDL mailing list