OpenGL sprite help

This is a discussion on OpenGL sprite help within the Game Programming forums, part of the General Programming Boards category; I'm making a sprite system for opengl; I can load the bitmaps (plural bitmaps, because there's an alpha mask) ok. ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    11

    OpenGL sprite help

    I'm making a sprite system for opengl; I can load the bitmaps (plural bitmaps, because there's an alpha mask) ok. I can make the quad ok. Then I render it. What is not ok is what happens when I try to draw other things on the screen. Even with an "alpha" component of 255 (completly on) weird things happen. For example, when I display a brown 16x16 quad after drawing a white rectangle, the white quad turns brown too. Here's the important parts of my code (tell me if there's something else I should include as important):

    This is in my initalization code:
    Code:
     glOrtho(0,W-1,H-1,0,1,-1);
     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
     glEnable(GL_TEXTURE_2D);
    W and H are the width and heigth of the screen, respectivly.

    This is how I create the texture:
    Code:
     /*Make the texture*/
     glGenTextures(1,&(f->tex));
     glBindTexture(GL_TEXTURE_2D,f->tex);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,final_bmp);
    w and h are the width and heigth of the texture, final_bmp is a pointer to the color+alpha chanel. f->tex is the tex id thingy.

    Finally, I draw the texture like this:
    Code:
     glBindTexture(GL_TEXTURE_2D,f->tex);
     glBegin(GL_QUADS);
     glTexCoord2f(0,0);
     glVertex2i(x,y+f->h);
     glTexCoord2f(1,0);
     glVertex2i(x+f->w,y+f->h);
     glTexCoord2f(1,1);
     glVertex2i(x+f->w,y);
     glTexCoord2f(0,1);
     glVertex2i(x,y);
     glEnd();
    x and y are the positions on the screen; they are representative of the upper left corner of the texture. f->h and f->w are the heigth and width of the texture, respectivly.

    Please help me. I'm really lost right now.

  2. #2
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Give them their own colors. Like for the box, you set it to white, then the squad with texture you set it to...whatever.
    Hello, testing testing. Everthing is running perfectly...for now

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    11

    Sorry

    I should have shown the code that draws the white box. Here it is:

    Code:
     glBegin(GL_QUADS);
     glColor3ub(255,255,255);
     glVertex2i(x1,y1);
     glVertex2i(x1,y2);
     glVertex2i(x2,y2);
     glVertex2i(x2,y1);
     glEnd();

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Before you draw the textured object color it full white, and before you draw the white box disable textures with glDisable(GL_TEXTURE_2D). Always keep in mind that OpenGL is a State Machine, so once you set a state, it remains that way until you change it.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    11

    Thanks

    That works! I'm one huge step closer to porting HIVE to opengl. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21