Thread: weird framerate

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    weird framerate

    I'm a bit puzzled with the framerate i'm getting with my engine written in OpenGL, on different machines.

    On my Pentium4 with a Radeon 9200SE 128MB vid-card, I was getting 30FPS with a 128x128 terrain, and 750x750x400 skybox. I tried it on my Athlon64 3000+ with the same vid-card, I got 16FPS with the same world. I then tried it on the P4 with the onboard video, and got 40-45FPS? Can anyone explain to me why this is? And also, how can I try and keep the FPS even on all processors and video-cards?

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well a lot of that may depend on the drivers for the video cards. They can make more of a difference than you think. As long as you are using time-based movement versus frame-based you should be pretty good. As long as it's > 30 you're fine really.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Mhmm....well i'm using frame-based as of now, and Iv'e also discovered that ATI dosn't have as good support for OGL as it does DX.....i'm gonna have to go back and overhaul the engine...its coded really bad anyway using slow methods....i'll need to allow it to render in either OGL or DX depending on the manufacturer of the users video-card.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    ati's support for OpenGL is just as good as any. To be honest, I don't quite think you appreciate how hard it would be to write the engine to support either DX or OpenGL. It's a LOT of work and to be honest, if you aren't writing commercial software, it's really not worth it.

    The speed issues can be resolved by optimizing code and algorithms. Hecks, it's also possible there's problems with how you measure framerates, although you haven't posted code so we likely can't tell.

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    Get your latest ATI drivers i think they just released the final part to their from scratch OpenGL driver rewrite... i think there may be more parts not sure but i thought 4.12 was the last part, they should run better.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    k thanks, i'll have a look at the new OGL drivers.

    the code does need to be optimized quite a bit, but with our without optimizations, the difference in FPS with and with out the card, and on different processors just startled me a bit, as I was expecting it to run faster on the AMD than the P4, and definatly not faster on the P4 without the card.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    erm...where would i go about download the new driver? Yes, google is my friend, but I still can't find it

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    i looked there, but for some reason i wasn't sure if it was the right driver...sorry.....maybe I should get some sleep.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  10. #10
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    also...are these new drivers for OGL only for XP??

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  11. #11
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    uh... you select you OS and card from the list boxes...

    i dont know if its XP only, never really said that i know of that would be stupid though...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  12. #12
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    >>uh... you select you OS and card from the list boxes...<<
    i know that...i was just wondering if the better support for OGL was only in the XP driver. My AMD machine is runnin Win2K (i fried me XP install disk). I downloaded the newest driver for that, and i'm still getting between 15 and 20FPS, although it is frairly smooth.
    Could it be the processors not the video card drivers? Ugh....I'm confused...lol

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  13. #13
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    not sure, probably its either in your code or the complexity of what your doing then...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    EDIT1 : i just made this post without reading this:

    its coded really bad anyway using slow methods
    which means you already know where your code is inefficient and i posted this for nothing
    just wondering, what types of things are you doing inefficiently?

    Now back to the original post

    Few questions (some of these should give you an idea of where to look for problems).

    -I have never worked with terrain, how many triangles does a 128x128 heightmap (I assume that's what that means) translate to? Is it any set amount, or does it depend on the heightmap density (or whatever).

    -Do you have backface culling on?

    -What does the third dimension of the skybox represent? I thought most typical skyboxes are just 5 2D quads, or a half sphere or something similar (this is just a question to help me out).

    -How many texture / material changes are you making per frame? Do you bind a texture per polygon?

    -How many texture passes are you doing per polygon? It's likely only one because you are just rendering terrain, but static lights and shadows can be compiled into a second darkmap (well, lightmap) texture, but the hardware has to take the time to look up and modulate (multiply) the color from each texture for each pixel, and this is quite time consuming (on some implementations, i.e for my own ATI card, of GL I've seen vertex lighting run faster).

    My guess is that all in all, you're pretty stuck. Post the following code:

    -FPS calculation code
    -The code you use to send polygons to OpenGL
    -the 'mainloop' of your application, i.e, all the high level steps your program goes through (including taking input, whatever you do to setup the renderer to render the scene, etc etc).

    Also, profile the code, see if it really is a rendering problem. I'd help you with profiling, but I can't currently get it working for my own IDE at the moment( I use visual C++ 6, although you can download an evaluation of Intel's VTune compiler which does an excellent job of profiling evidently).

    You aren't really giving us enough info for us to help you. If you do the things I suggested you will likely find the problem on your own. If you don't, people on this site will be able to better help you, and they will do so because they will see you are putting in effort.

    Good luck.
    EDIT:
    it's unlikely but possible both of your computers are just somehow retarded. You could post the exe and data so we could see if it runs crappy on our systems. I also have a p4 with an ati. Did you sayyou tried it on other computers or just your two? Although im pretty sure it really is code inefficiency and not your computers.
    Last edited by Darkness; 01-02-2005 at 08:28 PM.

  15. #15
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    I'll answer the questions first, and i'll post the code at the bottom.

    how many triangles does a 128x128 heightmap
    i'm not quite sure exactly how many....to get an idea i did a random terrain genoration in a 3D modeling program, except at 64x64, and it was upwards of 7000 triangles...so....alot

    Do you have backface culling on?
    yes, but it dosn't appear to make much difference on the framerate.

    What does the third dimension of the skybox represent? I thought most typical skyboxes are just 5 2D quads, or a half sphere or something similar (this is just a question to help me out).
    My skybox is 6 2D quads put together to form a cube. The 750x750 is length and width, and the x400 on the end is the height.

    now the last few questions you had are better answered if I post the code, so here it is:

    FPS calculation (Time Based):
    Code:
    			float g_FrameInterval = 0.0f;
    			static float framesPerSecond    = 0.0f;		// This will store our fps
    			static float lastTime			= 0.0f;		// This will hold the time from the last frame
    			static char strFrameRate[50] = {0};			// We will store the string here for the window title
    			
    			static float frameTime = 0.0f;				// This stores the last frame's time
    			
    			float currentTime = timeGetTime() * 0.001f;				
    			
    			g_FrameInterval = currentTime - frameTime;
    			frameTime = currentTime;
    			
    			++framesPerSecond;
    			
    			if( currentTime - lastTime > 1.0f )
    			{
    				// Here we set the lastTime to the currentTime
    				lastTime = currentTime;
    				
    				// Copy the frames per second into a string to display in the window title bar
    				sprintf(strFrameRate, "Edit Window | FPS: %d", int(framesPerSecond));
    				
    				// Set the window title bar to our string
    				SetWindowText(EditWin, strFrameRate);
    				
    				// Reset the frames per second
    				framesPerSecond = 0;
    			}
    Program Main loop:
    Code:
    // program main loop
    	while ( !bQuit ) {
    		
    		// check for messages
    		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
    			
    			// handle or dispatch messages
    			if ( msg.message == WM_QUIT ) {
    				bQuit = TRUE;
    			} else {
    				TranslateMessage( &msg );
    				DispatchMessage( &msg );
    			}
    			
    		} else {
    			g_Camera.Update(); //update camera
    			ProjMatrix(); //setup projection matrix 
    			
    			g_Camera.Look();
    			ModelMatrix(); //setup modelview matrix
    			
    			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //clear screen to black
    			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffers
    			
    			glPushMatrix();
    			DrawTerrain(0); //draw terrain
    			CreateSkyBox(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z, farclip + 1,  farclip + 1 , farclip/2 ); //draw skybox
    			
    			DrawCrosshair(g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z, TRUE); //draw crosshair
    			DrawHUD(); //draw HUD
    			
    			
    			glPopMatrix();
    			SwapBuffers( hDC );						
    		}
    		
    	}
    My code for rendering the terrain:
    Code:
    void DrawTerrain(int DrawWater)
    {
    	glActiveTextureARB		= (PFNGLACTIVETEXTUREARBPROC)		wglGetProcAddress("glActiveTextureARB");
    	glMultiTexCoord2fARB	= (PFNGLMULTITEXCOORD2FARBPROC)		wglGetProcAddress("glMultiTexCoord2fARB");
    	
    	FILE *pFile = fopen(filename, "rb");
    	
    	fread(&heightmap, TERRAIN_SIZE * TERRAIN_SIZE, 1, pFile);
    	fclose(pFile);
    	
    				
    				for (int z=0;z < TERRAIN_SIZE - 1.; ++z)
    				{
    					glActiveTextureARB(GL_TEXTURE0_ARB);
    					glEnable(GL_TEXTURE_2D);
    					glBindTexture(GL_TEXTURE_2D,  g_Texture[terraintex1id]);
    					glActiveTextureARB(GL_TEXTURE1_ARB);
    					glEnable(GL_TEXTURE_2D);
    					glBindTexture(GL_TEXTURE_2D,  g_Texture[terraintex2id]);
    					//glActiveTextureARB(GL_TEXTURE2_ARB);
    					//glEnable(GL_TEXTURE_2D);
    					//glBindTexture(GL_TEXTURE_2D,  g_Texture[0]);
    					glBegin(GL_TRIANGLE_STRIP);
    					
    					for (int x=0;x < TERRAIN_SIZE; ++x)
    					{
    						// render two vertices of the strip at once
    						float scaledHeight = heightmap[z * TERRAIN_SIZE + x] / SCALE_FACTOR;
    						float nextScaledHeight = heightmap[(z + 1)* TERRAIN_SIZE + x] / SCALE_FACTOR;
    						float color = 0.5f + 0.5f * scaledHeight / MAX_HEIGHT;
    						float nextColor = 0.5f + 0.5f * nextScaledHeight / MAX_HEIGHT;
    
    						
    						glColor3f(color, color, color);
    						glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat)x/TERRAIN_SIZE, (GLfloat)z/TERRAIN_SIZE);
    						glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (GLfloat)x/TERRAIN_SIZE, (GLfloat)z/TERRAIN_SIZE);
    						glVertex3f(static_cast<GLfloat>(x - TERRAIN_SIZE/2), scaledHeight, static_cast<GLfloat>(z - TERRAIN_SIZE/2));
    						
    						glColor3f(nextColor, nextColor, nextColor);
    						glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat)x/TERRAIN_SIZE, (GLfloat)(z+1)/TERRAIN_SIZE);
    						glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (GLfloat)x/TERRAIN_SIZE, (GLfloat)(z+1)/TERRAIN_SIZE);
    						glVertex3f(static_cast<GLfloat>(x - TERRAIN_SIZE/2), nextScaledHeight, static_cast<GLfloat>(z + 1 - TERRAIN_SIZE/2));	
    					}
    					glEnd();
    				}
    				
    				if(DrawWater == 1)
    				{
    					glColor4f(0.9f, 0.9f, 0.9f, 0.15f);
    					glEnable(GL_BLEND);	
    					glBlendFunc(GL_ONE, GL_ONE);
    					glActiveTextureARB(GL_TEXTURE0_ARB);
    					glEnable(GL_TEXTURE_2D);
    					glBindTexture(GL_TEXTURE_2D,  g_Texture[16]);
    					//glActiveTextureARB(GL_TEXTURE1_ARB);
    					//glEnable(GL_TEXTURE_2D);
    					//glBindTexture(GL_TEXTURE_2D,  g_Texture[0]);
    					//glActiveTextureARB(GL_TEXTURE2_ARB);
    					//glEnable(GL_TEXTURE_2D);
    					//glBindTexture(GL_TEXTURE_2D,  g_Texture[0]);
    					
    					glBegin(GL_QUADS);
    					glTexCoord2f(-40.0, 0.0);glVertex3f(-SEA_SIZE / 2, SEA_LEVEL, SEA_SIZE / 2);
    					glTexCoord2f(-40.0, 40.0);glVertex3f(-SEA_SIZE / 2, SEA_LEVEL, -SEA_SIZE / 2);
    					glTexCoord2f(40.0, 40.0);glVertex3f(SEA_SIZE / 2, SEA_LEVEL, -SEA_SIZE / 2);
    					glTexCoord2f(40.0, 0.0);glVertex3f(SEA_SIZE / 2, SEA_LEVEL, SEA_SIZE / 2);
    					glEnd();
    					glDisable(GL_BLEND);
    				}
    				
    				if(DrawWater == 1)
    				{
    					if(g_Camera.m_vPosition.y < OverlayElevation)
    					{
    						WaterOverlay(g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z);
    					}
    				}
    				
    }
    You could post the exe and data so we could see if it runs crappy on our systems. I also have a p4 with an ati. Did you sayyou tried it on other computers or just your two? Although im pretty sure it really is code inefficiency and not your computers.
    I only tried it on my two. If the code I provided dosn't help any, then i'll post the exe and the necessary files.
    Hopefully the code will provide enough info tho, but if not, let me know

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 11:23 PM
  2. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  3. Weird Characters With GetDlgItemText
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2006, 04:53 PM
  4. framerate vs refreshrate
    By hannibar in forum Game Programming
    Replies: 2
    Last Post: 03-15-2005, 04:40 PM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM