0,0 location and slow DrawPixel

Started by
2 comments, last by zedzeek 19 years, 4 months ago
Hi!! Im new to OpenGL and didnt found any way on other homepages tuts to change the default location of coordinates 0,0 from button left to top left :( Second, I only want to use DrawPixel function to draw to the screen. I dont want any 3D stuff. But just a simple DrawPixel call with dimension of 500x500 and RGBA does take 850ms, even in release mode. 1000x1000 then already needs 2750ms... Whats wrong? The window-creation is used from NeHe-Tutorials, and works just fine. All other code is made myself. This code follows the window creation, which is a window-mode 32bit one.

	ShowWindow(Window,SW_SHOW);
	SetForegroundWindow(Window);
	SetFocus(Window);

	glViewport(0, 0, _Screen.m_Width, _Screen.m_Height);
	glRenderMode(GL_RENDER);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, (GLdouble) _Screen.m_Width, 0.0, (GLdouble) _Screen.m_Height);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef (0.375, 0.375, 0.);
	glLoadIdentity();
This code is in the window-handler:

	case WM_PAINT:
		{
			glRasterPos2i(0, 0);
			memset(m_pScreen->m_pData, 0xFF, m_pScreen->m_Height * m_pScreen->m_Width *4);

			UINT Time = GetTickCount();
			glDrawPixels(m_Screen.m_Width, m_Screen.m_Height, GL_RGBA, GL_UNSIGNED_BYTE, m_pScreen->m_pData);
			UINT NeededTime = GetTickCount() - Time;
			glFlush();
			SwapBuffers(m_pScreen->m_DeviceContext);
			return 0;
		}
Whats wrong with the code? Thanks guys!
Advertisement
LOL, you don't use DrawPixel... That's slow as hell... The code is fine, you're just aware of how much information you're sending to your gfx card (read: a lot!)...

You will always draw in 3D with OpenGL, it's just a matter of how the camera's matrix is set up. You can use the orthographic view (like you're doing now) and draw triangles, quads and such instead of pixels... Of course, if you need it in pixels, that won't do you much good, but since you have not told us what you're drawing, then I cannot help you much more than this...
Killers don't end up in jailThey end up on a high-score!
There's nothing wrong with your code. glDrawPixels is notoriously slow on many implementations.

It sounds to me like you shouldn't really be using OpenGL at all, as it is primarily a 3D API. I would suggest looking into SDL instead, as it has much faster methods for manipulating raw pixel values in buffers.
for the first question i believe
gluOrtho2D(0.0, (GLdouble) _Screen.m_Width, (GLdouble) _Screen.m_Height), 0.0);
should do it, though be aware in maths the bottom left is normally 0,0
what card do u have if its a nvidia one then drawpixels is pretty quick

This topic is closed to new replies.

Advertisement