Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheShadow

Slow Program

This topic is 5543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement
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)

Share this post


Link to post
Share on other sites
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-~-

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> in your PrecalcTileCoords() function, instead of multiplying
> everything by 50, use bit-shifts.

That is SOO not going to help anything. On most modern CPUs, multiplies are as fast as adds, or a single clock cycle slower. Replacing a multiply with three shifts and adds is just ludicrous (unless you''re working on an Ameeeeegah or something from the stone age).

Try only drawing tiles that are actually in view on the screen.

Make sure you generate MIP maps for your tiles. If they''re 50x50 pixels on the screen, and you upload 256x256 textures, say, then the card would have to suck through much more data than necessary, unless you use MIP maps.

Make sure you''re drawing in hardware mode, if you''r using OpenGL. If glGetString(GL_VENDOR) says something about "Microsoft" then you lose.

Worst case, if your card has very little memory and your textures are enormous, try first drawing all tiles using texture X, then all tiles using texture Y, then all tiles using ...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What''s with all the sucking today?

NEAREST will not help. It will HURT! If you upload a texture that''s size 1024x1024, but the quad is only 10x10 pixels on the screen, which do you think is going to be fastest:

1) NEAREST filtering the 1024x1024 image (touching 4 MB of data)

2) LINEAR_MIPMAP_LINEAR filtering between a 16x16 and a 8x8 image (touching about 1.25 kB of data)


I''ll give you a hint: touching less data makes things faster on any modern computer system, as they''re all pretty much memory bound. I don''t understand why this is so hard to understand.

Share this post


Link to post
Share on other sites
I scaled my program and got a better speed... even though its still slow because of quad drawing... they are barely 100

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!