PDA

View Full Version : Simple Initialisation on existing Window



liturner
03-03-2012, 06:04 AM
Hi,

I am having real trouble finding a decent tutorial on how to simply initialise OpenGL on an existing HWND. I am normally a d3d / d2d programmer, but, for this application i need a pointer to the screen buffer, something I cant do in d2d. I have searched for a few hours now and all im finding is either out of date examples, or examples that create a window using OpenGL, or examples that include GLEW (also, what is GLEW?).

The requirements of my application are literally that I need to create an OpenGL "surface", using a specified, height, width and HWND. I then need a pointer to the backbuffer pixel so that I can manually modify the screen buffer pixel data. I then need to call "swap", "flip" or whatever command OpenGL uses to swap its screen buffers.

This is a 2D project. Normally I would use SDL but that forces window creation. Can somebody either point me at a GOOD recent tutorial to at least initilise the window. I do not know how OpenGL works at all, I have never used it.

If you are feeling generous I can figure it out off of the documentation if somebody could just post the function calls i will need. Im pretty confident that the whole app is only about 5 calls to OpenGL functions, but having never used OpenGL i dont even know where to start

Thanks

tonyo_au
03-03-2012, 06:11 AM
This will probably meet your needs
http://nehe.gamedev.net/tutorial/lessons_01__05/22004/

Some of the tutorials are dating but if you have never used OpenGL it will get you a long way.

tonyo_au
03-03-2012, 06:15 AM
This will probably meet your needs
http://nehe.gamedev.net/tutorial/lessons_01__05/22004/

Some of the tutorials are dating but if you have never used OpenGL it will get you a long way.

liturner
03-03-2012, 09:57 AM
That was helpfull thanks.

A few followup questions though.

- Do i have to "Release" either of the HDC, HGLRC. If so, what is the func name.
- Is there a PutPixels function in OpenGL with which i can pass it a pointer to an array of pixels?

Alfonse Reinheart
03-03-2012, 10:21 AM
Is there a PutPixels function in OpenGL with which i can pass it a pointer to an array of pixels?

Yes, but it (http://www.opengl.org/sdk/docs/man/xhtml/glDrawPixels.xml)'s going to be incredibly slow, so you shouldn't use it.

liturner
03-03-2012, 10:32 AM
Unfortunately, I will have to. I have to write a software renderer. I was hoping to use OpenGL for simply blitting to the screen. I would normally use SDL but my famework already has a HWND, and SDL only likes working with its own window (as far as i know).

the closest I have found in OpenGL is glDrawPixel(). Will this be what i would have to use after setting the rasteriser position? Or is there a func that works on purely XY screen space as glReadPixels() does?

liturner
03-03-2012, 10:33 AM
sorry, didnt see the hyperlink on the "it" word.

tonyo_au
03-03-2012, 10:48 PM
"Release" in OpenGL usually is done by assigining 0 to the object; for example


wglMakeCurrent(NULL,NULL);
if (c_hOpenGLRC)
{
wglDeleteContext(c_hOpenGLRC);
}

if (c_hWnd)
{
::ReleaseDC(c_hWnd,c_WindowDC);
}

liturner
03-04-2012, 11:22 AM
Thanks for the help. I have the majority set up now, but It seems to not work. Here is a few bits of my code;

PIXELFORMATDESCRIPTOR l_pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

Then afer initialisation I am filling an array of uint32 (packed rgba), and then calling;

glRasterPos2i(0, 0);
glDrawPixels(m_rtWidth, m_rtHeight, GL_RGBA, GL_INT, (const GLvoid*)this->m_pRenderTarget);
SwapBuffers(m_hDC);

I am not sure of what exactly i am doing wrong. My First guesses are the raster pos and the format / type of draw pixels. Pretty stuck.

liturner
03-04-2012, 11:31 AM
Also, I have just memset the array i am printing to 0x00111100. And it is still just showing a large white screen