Jump to content
  • Advertisement

Archived

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

LiamV

OpenGL Emulator Graphics using OpenGL

This topic is 5231 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

Hi, Im in the process of learning to program a console emulator. I have the CPU core, input done and so on, I initially used SDL to plot pixels upon a a byte array which i magnified and plotted using the SDL api. The only problem is that each for pixel in my virtual screen array (64x32 pixels), i have to iterate through my actual screen pixels (320x160). Thats ~100 million iterations before the screen is completely drawn. What I have decided to do is use the openGL api and use a textured quad for my screen and stretch the 64x32 texture to the 320x160 quad. The virtual screen array is defined: unsigned char Screen[64*32]; And each byte within the Screen array is either a 1 or a 0. My DrawScene and InitScene functions are below. Could someone please help me to load my Screen Array to a texture and blit it to the quad I have created. Many Regards, LiamV.
void InitScene()
{
	int vPort[4];
	glGetIntegerv(GL_VIEWPORT, vPort);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
}

void DrawScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);

	// Load Texture here


	glBegin(GL_QUADS);
	  glTexCoord2d(0,0);
	  glVertex2d(0,0);      //BL


          glTexCoord2d(0,1);
	  glVertex2d(0,160);    //TL


	  glTexCoord2d(1,1);
          glVertex2d(320,160);	//TR


	  glTexCoord2d(1,0);
          glVertex2d(320,0);	//BR

	glEnd();

	glDisable(GL_TEXTURE_2D);
	SwapBuffers(g_HDC);

	return;
}
[edited by - LiamV on May 29, 2004 1:50:50 PM] [edited by - LiamV on May 29, 2004 1:53:40 PM] [edited by - LiamV on May 29, 2004 1:56:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
Loading an array from system memory to video memory is very slow. Instead, I would suggest doing all of your drawing in OpenGL if you can. It is sort of pointless to use the CPU to draw your image and the GPU just to strech it. I suggest either using only OpenGL or only 2D/SDL/GDI. See if SDL has something like StrechBlit. I think it does, but that''s the wrong name.

Share this post


Link to post
Share on other sites
Thanks for that, it seems to work fine by stretching the SDL Surface. But for future reference could someone please answer my original problem by using OpenGL?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!