Sprite Engine in OGL
Hi, I''m writing a 2D Sprite Engine in OpenGL, but I have a few questions. I can''t get a bloody thing to display, all I have is a black screen. I''m using textured quads to display the "sprites." This is how I am initializing the viewing area:
glEnable (GL_TEXTURE_2D);
glEnable (GL_DEPTH_TEST);
glClearColor (0.0, 0.0, 0.0, 0.0);
glDepthFunc (GL_LESS);
glClearDepth (1.0);
glShadeModel (GL_SMOOTH);
glViewport (0, 0, 640, 480);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (0, 640, 480, 0, -100, 100);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
Note the Z values. I''m using that for sprite layers. Here is the code in my drawing callback function:
glClear (GL_COLOR_BUFFER_BIT);
glClear (GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef (0,0,0);
glPushMatrix();
glTranslatef (320, 240, 0);
glBindTexture (GL_TEXTURE_2D, Textures[1]) //yes, the texture works
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (-32, -32, 0);// Top Right Of The Quad Front
glTexCoord2f (1.0, 0.0);
glVertex3f (32, -32, 0); // Top Left Of The Quad Front
glTexCoord2f (1.0, 1.0);
glVertex3f (32, 32, 0); // Bottom Left Of The Quad Front
glTexCoord2f (0.0, 1.0);
glVertex3f (-32, 32, 0); // Bottom Right Of The Quad Front
glEnd();
glPopMatrix();
glutSwapBuffers();
Anyway, that should draw a 64x64 pixel textured quad, right? No go. I''ve tried translating above and below 0 on the Z axis, but still nothing is drawn. What am I not setting up properly?
My next question is collision detection. You can easily use bounding squares are bounding circles (its 2D, remember, so no bounding spheres etc. =) ) but has anyone devised a way for pixel-accurate collision detection in OGL that''s resonably fast? (a bounding square + the pixel method would probably be fast) I doubt its possible though.
And, my last question. Lighting in ortho! Null and Void mentioned he had some writing routines, but his website is dead/in a comma so =(. I''d just like to find a nice way for lighting in 2D ortho view. (At the worst, I could resort to colored transparent quads to "light" the ground etc.) Thanks!
-Dave
glTranslatef (0,0,0); does nothing whatsoever
try this until u see the quad on the screen
glClearColor (0.0, 0.0, 1.0, 0.0);
glDisable( GL_TEXTURE_2D );
glDisable( GL_LIGHTING );
glDisable( GL_CULL_FACE );
try also
//glTranslatef (320, 240, 0);
try this until u see the quad on the screen
glClearColor (0.0, 0.0, 1.0, 0.0);
glDisable( GL_TEXTURE_2D );
glDisable( GL_LIGHTING );
glDisable( GL_CULL_FACE );
try also
//glTranslatef (320, 240, 0);
if you wanna mail me the code, i''ll happily have a look ...
mark.shaxted@btinternet.com
Regards!!!
mark.shaxted@btinternet.com
Regards!!!
August 18, 2001 12:59 PM
I don''t think you''ll see anything if the Quad lies on Z-0, try doing glTranslatef(0.0f, 0.0f, -1.0f);
Well, I figured out why nothing was displaying. CodeWarrior was corrupted =). The code works fine now, after I replaced the old HD (norton disk doctor found lots of corrupted stuff, and bad blocks etc. The HD was old, it was failing, and I was too lazy to put in the new one I already had). That still leaves the question of lighting and collision detection. If I''m lucky, Null and Void will make an appearance =)
-Dave
-Dave
quote:
Original post by Dave the Embalmer
And, my last question. Lighting in ortho! Null and Void mentioned he had some writing routines, but his website is dead/in a comma so =(. I''d just like to find a nice way for lighting in 2D ortho view. (At the worst, I could resort to colored transparent quads to "light" the ground etc.) Thanks!
-Dave
My engine dynamically created GL_INTENSITY textures for lights, then using glColor and additive blending would render them over the rest of the scene. It was pretty much really simple shadow mapping, except with lights. It looked pretty good, and was relatively quick.
It had one problem though, you''d have to do one of two things to get it to not go through walls and other boundaries that light shouldn''t travel through: Generate a whole lot of light textures (you could make them really small, or put more than one on a texture and use texture coordinates) or use 32bit with a stencil buffer.
[Resist Windows XP''s Invasive Production Activation Technology!]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement