Using a quad which covers the entire screen it's uber slow

Started by
12 comments, last by Elefagente_Secreto 16 years, 11 months ago
Hi, I'm a beginner in OpenGL programming.. right now I'm trying to do a 2D asteroids game using SDL & OpenGL (using glOrtho projection). I made the ship and I can control it. Now I want to have a background image and I learned that I have two ways to do it: glDrawPixels and texture mapping (there are other ways to do it??). I tried both ways, and it works (the pic loads correctly and it appears in the screen), but the real problem here is the framerate. It slows down a lot.. the ship which moved so smoothly, now moves 2 frames per second. Don't know what the problem is.. Here is some code.. Please help me, and sorry for the bad english! Here in this code I loaded a texture and made a quad which covers the entire screen, showing the texture as a background. I also tried to tile smaller parts of the background to cover the screen, enabling and disabling GL_DEPTH, GL_SMOOTH, GL_BLEND, with or without display lists, but still slow. bool OpenGLEngine::Init() { // enable alpha blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); glShadeModel(GL_SMOOTH); // clear to black background glClearColor(0.0, 0.0, 0.0, 0.0); // crea muchos cubitos m_ship = new Ship(320,240,40); // loads texture LoadTexture("andro.bmp", &texture); dList = glGenLists(1); glNewList(dList , GL_COMPILE); glPushMatrix(); glEnable(GL_TEXTURE_2D); //glColor3f(0.2, 0.2, 0.6); glBindTexture(GL_TEXTURE_2D, textura); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(0, 0, 0); glTexCoord2f(1.0, 0.0); glVertex3f(100, 0, 0); glTexCoord2f(1.0, 1.0); glVertex3f(100, 100, 0); glTexCoord2f(0.0, 1.0); glVertex3f(0, 100, 0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glPopMatrix(); glEndList(); return true; } void OpenGLEngine::SetupProjection(int width, int height) { if (height == 0) // don't want a divide by zero { height = 1; } glViewport(0,0, width, height); // reset the viewport to new dimensions glMatrixMode(GL_PROJECTION); // set projection matrix current matrix glLoadIdentity(); // reset projection matrix glOrtho( 0, width, height, 0, -1, 1 ); glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // reset modelview matrix m_windowWidth = width; m_windowHeight = height; } void OpenGLEngine::Prepare(float dt) { m_ship->Move(dt); } void OpenGLEngine::Render() { // clear screen and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // resets the model-view matrix glLoadIdentity(); // background glCallList(dList); // shows the ship m_ship->Show(); glColor3f(1.0,1.0,1.0); }
Advertisement
I forgot to say whats my computer's specs! (I don't know if its necessary)

Graphics card: Geforce 4 MX 440 64 Mb VRam
CPU: AMD Athlon 2500+
OS: Windows XP SP2


Quake III Arena works perfectly!!
How big is your background texture image?
First I used a 512x512 texture, but then I tried a 16x16 texture and it's the same. I forgot to say that I tried without a texture, only a colored quad.. Without textures it's a bit faster, but still slow..
Last thing, here's a list of frame rates and screen resolutions:

320x240x32 = 45.4545 fps
640x480x32 = 11.7647 fps
1024x768x32 = 4.58716 fps

Please, I really need to know what the problem is, so I can continue to learn and experiment with OpenGL!
Quote:Original post by BeethovenKLC
Last thing, here's a list of frame rates and screen resolutions:

320x240x32 = 45.4545 fps
640x480x32 = 11.7647 fps
1024x768x32 = 4.58716 fps

Please, I really need to know what the problem is, so I can continue to learn and experiment with OpenGL!


The first thing that comes to my mind is... if you don't render the ship, does the framerate improve?? How fast it is if you only render the ship?? I'd also try disabling both blending and depth testing while drawing the background...

Are you sure you've got an hardware accelerated pixel format ?

Y.
I tried enabling and disabling alpha blending and I got better results without applying textures.
Apart from GL_TEXTURES_2D and GL_BLEND in some tests, all else is disabled.
It's the same if I dont use GL_SMOOTH.


1. Background with a 32x32 texture. No ship. Alpha Blending enabled & disabled.
320x240x32 = 45.4545 fps
640x480x32 = 11.7647 fps
1024x768x32 = 4.58716 fps


2. Background with a 32x32 texture. With ship. Alpha Blending enabled & disabled.
320x240x32 = 45.4216 fps
640x480x32 = 11.4551 fps
1024x768x32 = 4.44611 fps


3. Colored background without texture. With ship. Alpha Blending enabled.
320x240x32 = 100 fps
640x480x32 = 25.641 fps
1024x768x32 = 9.90099 fps


3. Colored background without texture. With ship. Alpha Blending disabled.
320x240x32 = 100 fps
640x480x32 = 25.641 fps
1024x768x32 = 9.90099 fps


4. Colored background without texture. With ship. Alpha Blending disabled.
320x240x32 = 1000 fps
640x480x32 = 166.667 fps
1024x768x32 = 71.4286 fps


5. No background (no quad). With ship.
320x240x32 = 1000 fps
640x480x32 = 200 fps
1024x768x32 = 90.9091 fps




The background is a big quad covering the entire screen, with or without texture.
The ship's size is about 20x20 (its only a triangle).
I tried tiling up the same texture to cover the screen with multiple quads but the fps is still the same (the fps doesn't drop either).
Quote:Original post by BeethovenKLC
3. Colored background without texture. With ship. Alpha Blending disabled.
320x240x32 = 100 fps
640x480x32 = 25.641 fps
1024x768x32 = 9.90099 fps


4. Colored background without texture. With ship. Alpha Blending disabled.
320x240x32 = 1000 fps
640x480x32 = 166.667 fps
1024x768x32 = 71.4286 fps
....


Those results are interesting, could you post your code for us to look at?? if you cannot post the whole code, at least the window setup and texture loading/setup would be interesting.
I think you made an error on items 3 & 4 they have the same specs, with considerably different fps.


Is this your problem:

Quote:

LoadTexture("andro.bmp", &texture);

glBindTexture(GL_TEXTURE_2D, textura);



In LoadTexture the variable 'texture' ending with an 'E'

And glBindTexture the variable 'textura' ending with an 'A'
Nicholas ChristopherArchitecture Software Developer, 3D Modelerhttp://www.arconovum.com

This topic is closed to new replies.

Advertisement