Archived

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

wall

Drawing to a Bitmap

Recommended Posts

Hi! I''m trying to draw to a bitmap with OpenGL. The problem is that the rendered image appears in the top right corner of the bitmap. Everything works fine if I render to a normal window though. Help would be apreciated. Here''s my code: HDC DC; HBITMAP Bitmap; BITMAPINFO Info; byte *Bits; DC = CreateCompatibleDC(NULL); memset(&Info, 0, sizeof(Info)); Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); Info.bmiHeader.biWidth = ThisImage->m_uiWidth; Info.bmiHeader.biHeight = ThisImage->m_uiHeight; Info.bmiHeader.biPlanes = 1; Info.bmiHeader.biBitCount = 24; Info.bmiHeader.biCompression = BI_RGB; Bitmap = CreateDIBSection(DC, &Info, DIB_RGB_COLORS, (void**)&Bits, NULL, 0); SelectObject(DC, Bitmap); PIXELFORMATDESCRIPTOR pfd; int PixelFormat; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cRedBits = 8; pfd.cGreenBits = 8; pfd.cBlueBits = 8; pfd.cDepthBits = 0; PixelFormat = ChoosePixelFormat(DC, &pfd); SetPixelFormat(DC, PixelFormat, &pfd); HGLRC RC; RC = wglCreateContext(DC); wglMakeCurrent(DC, RC); SetViewport(); DrawImage();

Share this post


Link to post
Share on other sites
I could understand it if your image was vertically flipped (the DIB section you''re creating is upside down. To get the top-left of the image to be the first line in memory you need to pass a negative height in the BITMAPINFOHEADER. What viewport and projection settings are you using?



Iain Hutchison
Programmer, Silicon Dreams
The views expressed here are my own, not those of my employer.

Share this post


Link to post
Share on other sites
Here''s my viewport/projection settings:

glViewport(0, 0, Width, Height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0, Width, 0, Height, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Again, you can only see the bottom left corner of the rendered image in the top right corner of the bitmap...So it''s like the image has been moved up and to the right. =)

Share this post


Link to post
Share on other sites