Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL for emulator programming

Started by Milkies Jul 14, 2008 at 3:23 PM 3 replies 1.1k views
Original Post
Milkies
Milkies
Hi Guys, I have wrote a gameboy emulator that seems to be working great, however im having speed issues with the graphic emulation with opengl. I know next to nothing about OpenGL because i've never needed it except this one small function in my emulators. Hopefully if I describe how im doing things you might be able to suggest a speedier way of doing things. Here is my current code:

unsigned char screenData[160][144][3];
void RenderGame()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRasterPos2i(-1, 1);
glPixelZoom(1, -1);
glDrawPixels(160, 144, GL_RGB, GL_UNSIGNED_BYTE, screenData);
SDL_GL_SwapBuffers( ) ;
glFlush();
}
The above code is supposed to be called 60 times a second. Thats all the opengl in my emulator. As I said it works fine, just not fast enough. It runs at 60FPS on my machine but its a pretty fast machine. On my slow Asus EEE it runs at about 20FPS whereas a playstation emulator runs at 50FPS. So if a playstation emulator runs at 50FPS surely my gameboy emulator can run at 60FPS. The way I calculate the contents of the screenData variable is the same way the original gameboy does. It colours each pixel at a time depending on what horizontal row is currently being drawn. Someone recommeded a dirty rectangle but I dont know how that would work. Also one other issue im having. The current resolution is 160x144 but i want the user to be able to make it bigger by pressing keyboard key '+' (which i can detect in opengl). How would I edit the above code so it changed the display to x2 of its current resolution? Thanks for any help
V-man
V-man
http://www.opengl.org/wiki/index.php/Common_Mistakes#glDrawPixels

and also

http://www.opengl.org/wiki/index.php/Common_Mistakes#glFinish_and_glFlush
Milkies
Milkies
Thanks for the reply.

I made the changes and it did improve it a bit. Anyone else have any ideas or a way to do the scaling i mentioned?

Thanks again
stonemetal
stonemetal
Does Opengl net you anything in this case? Sdl comes with support for doing bit blits directly instead of going through opengl.

Topic Locked

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

Sign in to reply to this topic.