Skip to main content
gamedev.net
🔒 Locked

Slow Program

Started by TheShadow Apr 17, 2003 at 10:01 PM 15 replies 550+ views
Original Post
TheShadow
TheShadow
Im having trouble on drawing quads ... im drawing them into the screen very slowly... I previously thought my texturing was the problem but no... it runs the same with textures (just a bit slower but nothing really so significant) but without textures my quad drawing makes my player quad move slow... See here is my code
  

int draw_tiles(GLvoid)
{
  int tile;
   glLoadIdentity();
  for (int y = 0; y < MAP_SIZEY; y++)
  {
    for (int x = 0; x < MAP_SIZEX; x++)
    {
	
    tile = map[y][x];

  glBindTexture(GL_TEXTURE_2D, texture[tile]);
  glBegin(GL_QUADS);

    glTexCoord2f(0.0f, 1.0f); glVertex2f(tiles[x][y].tlVertex_x, tiles[x][y].tlVertex_y);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(tiles[x][y].trVertex_x, tiles[x][y].trVertex_y);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(tiles[x][y].blVertex_x, tiles[x][y].blVertex_y);
    glTexCoord2f(0.0f, 0.0f); glVertex2f(tiles[x][y].brVertex_x, tiles[x][y].brVertex_y );
   
	glEnd();
    }
	
  }
   

  return (1);
}

  
And here is where i have calculated previously my coordinates
  

void PrecalcTileCoords(GLvoid)
{
	for (int y = 0; y < MAP_SIZEY; y++)
  {
    for (int x = 0; x < MAP_SIZEX; x++)
    {
	tiles[x][y].tlVertex_x = float(x)*50;
	tiles[x][y].tlVertex_y = float(y)*50;
	tiles[x][y].trVertex_x = float(x+1)*50;
	tiles[x][y].trVertex_y = float(y)*50;
	tiles[x][y].blVertex_x = float(x+1)*50;
	tiles[x][y].blVertex_y = float(y+1)*50;
	tiles[x][y].brVertex_x = float(x) * 50;
	tiles[x][y].brVertex_y = float(y + 1) * 50;
    
    }
	
  }
}
  
My player movement function is A-OK for now because without the map drawing the player quad moves very smoothly Mecha Engineer (Making Real Humanoid Suits)
Mecha Engineer (Making Real Humanoid Suits)
TheShadow
TheShadow
C:\Program Files\Microsoft Visual Studio\MyProjects\mge\glEngine.cpp(47) : error C2296: ''<<'' : illegal, left operand has type ''float''

that''s what shifting gave me

Mecha Engineer (Making Real Humanoid Suits)
Mecha Engineer (Making Real Humanoid Suits)
cowsarenotevil
cowsarenotevil
quote:
Original post by TheShadow
C:\Program Files\Microsoft Visual Studio\MyProjects\mge\glEngine.cpp(47) : error C2296: ''<<'' : illegal, left operand has type ''float''

that''s what shifting gave me

Mecha Engineer (Making Real Humanoid Suits)


I think you can only shift integers.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
TheShadow
TheShadow
Yeah im going to use typecasting


(GLfloat)((x) << 5) + ((x) << 4) + ((x) << 1);

Mecha Engineer (Making Real Humanoid Suits)

[edited by - TheShadow on April 17, 2003 11:28:52 PM]
Mecha Engineer (Making Real Humanoid Suits)
TheShadow
TheShadow
Nope no improvement... same thing

Mecha Engineer (Making Real Humanoid Suits)
Mecha Engineer (Making Real Humanoid Suits)
noixtirdoe
noixtirdoe
you''re right; sorry.

-noix-

In this world gone mad, we won''t spank the monkey; the monkey will spank us.
In this world gone mad, we won't spank the monkey; the monkey will spank us.
TheShadow
TheShadow
I scaled my program and got a better speed... even though its still slow because of quad drawing... they are barely 100
Mecha Engineer (Making Real Humanoid Suits)
kdogg
kdogg
You might want to try taking out all your calls to glBegin and glEnd. Just call glbegin before your loop and glend after your loop.

Do you have to calculate the tile coordinates before every call to draw_tiles?
Ilici
Ilici
hope u have a main loop with
do
{

} while (running);

not windows message stuff

and i dont think u need to precalculate texcoords

ah and dont bind the texture every time


[edited by - Ilici on April 18, 2003 3:27:55 PM]
higherspeed
higherspeed
How wide is your grid? If it was about 100, then that would be 20000 polys. But if by 100, you mean 10 by 10 then that''s nothing. 20000 polys can really slow it down on older computers, I must admit I don''t know of any figures. Finally, isn''t that a strange way of drawing tiles, wouldn''t it be far easier to draw one quad for your whole level and tile the texture. Unless you''re going to expand the program and make a rough surface. Or am I missing the point somewhere?
kdogg
kdogg
Another thing to consider is drawing all the quads with the same texture at the same time instead of having to bind a texture for each quad, but i don''t know how your program''s setup.
TheShadow
TheShadow
Well i cant really texture all my quads with the same texture because its a tile engine... that would be nonsense... but about texturing only one big quad... with different textures inside it? that would be interesting... i'm new to ogl so i didn't know that could be done... could you initiate me in that? Even though my player quad moves at the same speed when i use a one 10*10 quad then when i use 100 1*1 quads

[edited by - TheShadow on April 18, 2003 5:21:36 PM]
Mecha Engineer (Making Real Humanoid Suits)
Luctus
Luctus
quote:
Original post by TheShadow
... but about texturing only one big quad... with different textures inside it? that would be interesting... i''m new to ogl so i didn''t know that could be done...


Nope, can''t be done.

quote:
Original post by Ilici
hope u have a main loop with
do
{
} while (running);
not windows message stuff



AP: I don''t think he meant you should throw out windows message processing, just that you shouldn''t use the message pump as game loop.

What you want to do is:
1) Sort the tiles by texture so you set one texture, and then draw all tiles that uses that texture, then set next texture, draw all tiles using that texture..and so on. Setting textures are VERY performance expensive.

2) Use vertex arrays to gain some serious speed, or at least try to get rid of as many glBegin/glEnd as possible.

Instead of doing:

for ( ... )
{
glBegin( GL_QUADS );
glVertex2f(...);
glVertex2f(...);
glVertex2f(...);
glVertex2f(...);
glEnd();
}

you do:

glBegin( GL_QUADS );
for ( ... )
{
glVertex2f(...);
glVertex2f(...);
glVertex2f(...);
glVertex2f(...);
}
glEnd();


3) Only draw those tiles that are visible

Most of this has already been said..but..


-Luctus
Codito, Ergo Sum (Courtesy of ThinkGeek)

[Mail][DreggSoft]
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.