OpenGL lag problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:Missing lua51.dll.
GodDamn I knew I would have forgotten 1 dll

http://rapidshare.com/files/412570094/lua.zip
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

Okay, it ran.

Mario walks around smoothly, didn't notice bad framerate at all.
When you scroll the map, it's supposed to be jittery because it moves by a full tile each time, right?

So, it ran good for me.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:Okay, it ran.

Mario walks around smoothly, didn't notice bad framerate at all.
When you scroll the map, it's supposed to be jittery because it moves by a full tile each time, right?

So, it ran good for me.

Yeah thats fine with the tiles moving one tile at a time

Does mario walk faster when you scroll out of the map?
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

Oh yes, he runs at about half the speed when he's in the tiled area. I'm not so sure it's a rendering issue though. How does your main loop look and how are you capping the logic framerate?
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:Oh yes, he runs at about half the speed when he's in the tiled area. I'm not so sure it's a rendering issue though. How does your main loop look and how are you capping the logic framerate?

Code: Select all


	if ( SDL_GetTicks() - CurrentTick > 1000 ) {
		if ( CurrentFrame > MaxFPS ) {
			SDL_Delay( ( ( 1000 / MaxFPS ) - (SDL_GetTicks() - CurrentTick ) ) );  // Delay the nessacary
			CurrentFrame = 0;
		}
	}
Thats how I cap frame rate but when maps are rendering my CPU is allways at 50% (dual core) so it suggests to me that it is a rendering problem whats you're CPU usage at?

EDIT: Lol sorry for the lack of comments and the unfamilar syntax of my engine

Also here's my main function and my loop

int main ( int argc,char* args[] ) {

System system;

system.Initialize(false);

Map::GetInstance()->Load("Data/map.map","Data/DemoTileSet.png");
Players *Party = Players::GetInstance();
Party->InitPlayer(0);
Party->LoadPlayerTex(0,"Data/Images/Mario.png");

Map *NewMap = Map::GetInstance();

while ( system.Loop() ) {
NewMap->Render();
Party->UpdatePlayers(0);
system.Sync();
}

return 0;
}


But my point is, is that if I were using glut It would hack through this at like 20% CPU

Idk if this is the problem it could be the loop I use for my 512x512 spritesheets

Basicly my map arrays take a integer ID like so

so if the ID = 1

OnSpriteSheet
X = 32 and Y = 0

if the ID = 2

OnSpriteSheet
X = 64 Y = 0

if ID = 17

OnSpriteSheet
X = 0 Y = 32


Here's how I handle that

Code: Select all


void Map::Render() {

if ( Key[SDLK_a] ) {
	Camera::GetInstance()->SetX( Camera::GetInstance()->GetX() - 0.3f );
}
if ( Key[SDLK_d] ) {
	Camera::GetInstance()->SetX( Camera::GetInstance()->GetX() + 0.3f );
}
if ( Key[SDLK_w] ) {
	Camera::GetInstance()->SetY( Camera::GetInstance()->GetY() - 0.3f );
}
if ( Key[SDLK_s] ) {
	Camera::GetInstance()->SetY( Camera::GetInstance()->GetY() + 0.3f );
}

glBindTexture(GL_TEXTURE_2D,Texture);
glEnable( GL_TEXTURE_2D );

for ( float x = Camera::GetInstance()->GetX() + 16;x < Camera::GetInstance()->GetX() + Camera::GetInstance()->GetWidth();x += 32 ) {
	for ( float y = Camera::GetInstance()->GetY() + 16;y < Camera::GetInstance()->GetY() + Camera::GetInstance()->GetHeight();y += 32 ) {
		for ( int LAYER = 0;LAYER < 2;LAYER++ ) {

			if ( x >= MapW * 32 || x < 0 || y >= MapH * 32 || y <= 0 ) {
				continue;
			}

			if ( Tile[LAYER][(int)x / 32][(int)y / 32] < 0 ) {
				continue;
			}


				for ( int i = 0; i < 16;i++ ) {
					if ( ( Tile[LAYER][(int)x / 32][(int)y / 32] - (i * 16) ) < 16 ) {

						CropX = ( Tile[LAYER][(int)x / 32][(int)y / 32] - (i * 16) ) * 32;
						CropY = i * 32;

						glPushMatrix();

						glColor3f(1,1,1);
						glTranslatef(x - Camera::GetInstance()->GetX(),y - Camera::GetInstance()->GetY(),0);
						glBegin( GL_QUADS );

						glTexCoord2f(CropX / 512,CropY / 512); glVertex2f(-32 / 2,-32 / 2);

						glTexCoord2f( ( CropX + 32 ) / 512,CropY / 512 );  glVertex2f(32 / 2,-32 / 2);

						glTexCoord2f( (CropX + 32 ) / 512, ( CropY + 32 ) / 512);  glVertex2f(32 / 2,32 / 2);

						glTexCoord2f(CropX / 512, ( CropY + 32 ) / 512); glVertex2f(-32 / 2,32 / 2);

						glEnd();

						glPopMatrix();
						break;
					}
		}

		
		}

}

}
}


for ( int i = 0; i < 16;i++ ) {
if ( ( Tile[LAYER][(int)x / 32][(int)y / 32] - (i * 16) ) < 16 ) {

CropX = ( Tile[LAYER][(int)x / 32][(int)y / 32] - (i * 16) ) * 32;
CropY = i * 32;

glPushMatrix();

glColor3f(1,1,1);
glTranslatef(x - Camera::GetInstance()->GetX(),y - Camera::GetInstance()->GetY(),0);
glBegin( GL_QUADS );

glTexCoord2f(CropX / 512,CropY / 512); glVertex2f(-32 / 2,-32 / 2);

glTexCoord2f( ( CropX + 32 ) / 512,CropY / 512 ); glVertex2f(32 / 2,-32 / 2);

glTexCoord2f( (CropX + 32 ) / 512, ( CropY + 32 ) / 512); glVertex2f(32 / 2,32 / 2);

glTexCoord2f(CropX / 512, ( CropY + 32 ) / 512); glVertex2f(-32 / 2,32 / 2);

glEnd();

glPopMatrix();
break;
}
}

Maybe doing this for each tile could be the problem? ( alothough glut would still handle this with ease )
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

My CPU was at 12%, it was sitting at 6% before running your app. I didn't look at that code yet, I'll edit this in a bit.

I keep having to end the task to quit, is there an exit key? lol
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:My CPU was at 12%. I didn't look at that code yet, I'll edit this in a bit.

I keep having to end the task to quit, is there an exit key? lol
Lol sorry about that, I wonder why it would slow down if you're CPU was a only at 12%.......Maybe its just my shitty PC and I'm not capping the framerate correctly...I'm confused I've been trying to firgure this out for days now :x
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

N64vSNES wrote:
X Abstract X wrote:My CPU was at 12%. I didn't look at that code yet, I'll edit this in a bit.

I keep having to end the task to quit, is there an exit key? lol
Lol sorry about that, I wonder why it would slow down if you're CPU was a only at 12%.......Maybe its just my shitty PC and I'm not capping the framerate correctly...I'm confused I've been trying to firgure this out for days now :x
I think 12% might be deceiving. My CPU is quad core, hyperthreaded, and 1/8 of 100% is 12.5%. As far as I know, applications will use as much CPU as they can get, an entire core if possible.

So, essentially both of us were using 100% of a core, which is normal.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

What is CurrentTick?
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:What is CurrentTick?
CurrentTick is the time that has alapsed
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

N64vSNES wrote:
X Abstract X wrote:What is CurrentTick?
CurrentTick is the time that has alapsed
Time elapsed since the start of program? That would translate to:

Code: Select all

if (0 > 1000) {
    if (CurrentFrame > MaxFPS) {
        SDL_Delay(1000 / MaxFPS);
        CurrentFrame = 0;
    }
}
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

http://rapidshare.com/files/412705189/newbuild.zip
Ok so here is the new, I realised that my frame rate was fucked and was capping it wrong So try it know and also see if the is any diffrence when you use another openGL dll ( I doubt it'll make a diffrence but its worth a try )
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

N64vSNES wrote:http://rapidshare.com/files/412705189/newbuild.zip
Ok so here is the new, I realised that my frame rate was fucked and was capping it wrong So try it know and also see if the is any diffrence when you use another openGL dll ( I doubt it'll make a diffrence but its worth a try )
It's still screwed. As far as I can tell, you didn't supply an OpenGL dll so it's been using the one in my win32 folder.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL lag problem

Post by N64vSNES »

X Abstract X wrote:
N64vSNES wrote:http://rapidshare.com/files/412705189/newbuild.zip
Ok so here is the new, I realised that my frame rate was fucked and was capping it wrong So try it know and also see if the is any diffrence when you use another openGL dll ( I doubt it'll make a diffrence but its worth a try )
It's still screwed. As far as I can tell, you didn't supply an OpenGL dll so it's been using the one in my win32 folder.
Well I've fixed it, its not exactly glut speed but its a hell of a lot faster, I gave it a newer openGL DLL and it runs with maps rendering at 30-40% CPU at 60 FPS however before it was at 50% (dual core) at about 30-40 FPS when maps were rendering :)
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: OpenGL lag problem

Post by X Abstract X »

N64vSNES wrote:
X Abstract X wrote:
N64vSNES wrote:http://rapidshare.com/files/412705189/newbuild.zip
Ok so here is the new, I realised that my frame rate was fucked and was capping it wrong So try it know and also see if the is any diffrence when you use another openGL dll ( I doubt it'll make a diffrence but its worth a try )
It's still screwed. As far as I can tell, you didn't supply an OpenGL dll so it's been using the one in my win32 folder.
Well I've fixed it, its not exactly glut speed but its a hell of a lot faster, I gave it a newer openGL DLL and it runs with maps rendering at 30-40% CPU at 60 FPS however before it was at 50% (dual core) at about 30-40 FPS when maps were rendering :)
For me, it takes 7 seconds for mario to cross in the tiled area, 4.5 seconds to cross in the empty area. That is definitely not normal, even if the game renders at 20 FPS you probably want the simulation to run at a constant speed. If that bothers you, you could check out http://gafferongames.com/game-physics/f ... -timestep/ and work on decoupling the simulation speed from the rendering speed.
Post Reply