Sdl + opengl noob question

I’m not certain exactly what the error you are having. Is it not compiling? Is it leaving white boxes?

Aside from that… not sure. if it compiles and runs you might put up a screenshot of what it’s doing.

slicedpan wrote:> Hi, i’m writing what is possibly the beginning of some sort of 2d platformer with physics. I’m struggling with this one particular section of my rendering code. I have been reading some tutorials and most of the following code works. I have some simple polys rendering in world coordinates, then an overlay that renders on top using the same coords as the screen. however am trying to implement some textures and i just can’t seem to get them to work. I’m sure i’ve just done something really stupid, anyway heres the code:

Code:

void CMyEngine::Render( SDL_Surface* pDestSurface )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

glPushMatrix();
gluOrtho2D(campos_x, (SCRWIDTH/SCALE) + campos_x, campos_y, (SCRHEIGHT / SCALE) + campos_y);
prim_cont->Draw();
glPopMatrix(); // this part renders the physics object using solid color polys, this works

glPushMatrix();
gluOrtho2D(0,SCRWIDTH,0,SCRHEIGHT);
ol_cont->Draw();
glPopMatrix(); // this part renders the overlay, this works too


glEnable(GL_TEXTURE_2D); //this code should hopefully draw a textured rectangle on the screen
glEnable(GL_BLEND);
glColor4d(1, 1, 1, 0.75);

glPushMatrix();
gluOrtho2D(0,SCRWIDTH,0,SCRHEIGHT);    
glBindTexture(GL_TEXTURE_2D, G.tex);    // G.tex holds the texture number, i've checked and it's not equal to zero
glBegin(GL_QUADS);    
    glTexCoord2i(0,0);glVertex2d(0.0,0.0);
    glTexCoord2i(0,1);glVertex2d(0.0,258.0);
    glTexCoord2i(1,1);glVertex2d(387.0,258.0);
    glTexCoord2i(1,0);glVertex2d(387.0,0.0);
glEnd();
glPopMatrix();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

SDL_GL_SwapBuffers();

}

The code that loads the texture is taken from here (http://anomtech.uuuq.com/Index.php?page=glTextures), i’ve checked that guys source and it compiles and shows the same texture correctly. any help would be much appreciated thanks.

Hi Micah,

unless my eyes deceive me, it appears as if you’re doing rendering while the
projection matrix mode is set (or alternatively,
trying to change the projection while in the model view mode)…

maybe try something like:

glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0,SCRWIDTH,0,SCRHEIGHT); glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

//this code should hopefully draw a textured rectangle on the screen
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glColor4d(1, 1, 1, 0.75);

glBindTexture(GL_TEXTURE_2D, G.tex);    // G.tex holds the texture

number, i’ve checked and it’s not equal to zero
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex2d(0.0,0.0);
glTexCoord2i(0,1);glVertex2d(0.0,258.0);
glTexCoord2i(1,1);glVertex2d(387.0,258.0);
glTexCoord2i(1,0);glVertex2d(387.0,0.0);
glEnd();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

//pop the modelview stack
glPopMatrix();

//pop the projection stack
glPopMatrix();

hth,
ErikOn Thu, Mar 11, 2010 at 11:23 AM, MBrening <micah.brening at gmail.com> wrote:

I’m not certain exactly what the error you are having. Is it not
compiling? Is it leaving white boxes?

Aside from that… not sure. if it compiles and runs you might put up a
screenshot of what it’s doing.

slicedpan wrote:

Hi, i’m writing what is possibly the beginning of some sort of 2d
platformer with physics. I’m struggling with this one particular section of
my rendering code. I have been reading some tutorials and most of the
following code works. I have some simple polys rendering in world
coordinates, then an overlay that renders on top using the same coords as
the screen. however am trying to implement some textures and i just can’t
seem to get them to work. I’m sure i’ve just done something really stupid,
anyway heres the code:

Code:

void CMyEngine::Render( SDL_Surface* pDestSurface )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

glPushMatrix();
gluOrtho2D(campos_x, (SCRWIDTH/SCALE) + campos_x, campos_y, (SCRHEIGHT

/ SCALE) + campos_y);
prim_cont->Draw();
glPopMatrix(); // this part renders the physics object using solid
color polys, this works

glPushMatrix();
gluOrtho2D(0,SCRWIDTH,0,SCRHEIGHT);
ol_cont->Draw();
glPopMatrix(); // this part renders the overlay, this works too


glEnable(GL_TEXTURE_2D); //this code should hopefully draw a textured

rectangle on the screen
glEnable(GL_BLEND);
glColor4d(1, 1, 1, 0.75);

glPushMatrix();
gluOrtho2D(0,SCRWIDTH,0,SCRHEIGHT);
glBindTexture(GL_TEXTURE_2D, G.tex);    // G.tex holds the texture

number, i’ve checked and it’s not equal to zero
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex2d(0.0,0.0);
glTexCoord2i(0,1);glVertex2d(0.0,258.0);
glTexCoord2i(1,1);glVertex2d(387.0,258.0);
glTexCoord2i(1,0);glVertex2d(387.0,0.0);
glEnd();
glPopMatrix();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

SDL_GL_SwapBuffers();

}

The code that loads the texture is taken from herehttp://anomtech.uuuq.com/Index.php?page=glTextures,
i’ve checked that guys source and it compiles and shows the same texture
correctly. any help would be much appreciated thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Erik Yuzwa
I’d love to help out! Find me on:


http://www.erikyuzwa.com
http://www.twitter.com/eyuzwa