Thread: OpenGL with WIN 32

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    87

    Angry OpenGL with WIN 32

    Hello,
    I'm learning OpenGL, but I have lots of troubles at startup!
    I want to draw some stuff in a window, so I "create" rendering context and make it corrent.After all I release and delete the device, but it don't work. I do this all in the window procedure as follows:
    Code:
    ....
    case WM_CREATE:
    		PIXELFORMATDESCRIPTOR pfd;
    		hDC = ::GetDC(hwnd);
    		ZeroMemory( &pfd, sizeof( pfd ) );
    		pfd.nSize = sizeof( pfd );
    		pfd.nVersion = 1;
    		pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
                 PFD_DOUBLEBUFFER;
    		pfd.iPixelType = PFD_TYPE_RGBA;
    		pfd.cColorBits = 24;
    		pfd.cDepthBits = 16;
    		pfd.iLayerType = PFD_MAIN_PLANE;
    		iFormat = ChoosePixelFormat( hDC, &pfd );
    		SetPixelFormat( hDC, iFormat, &pfd );
    		hRC = wglCreateContext( NULL );
    		hRC = wglCreateContext( hDC );
    		if(!wglMakeCurrent( hDC, hRC ))
    			MessageBox (NULL, "Main Window Initialization ERROR!",
    				"OpenGL Tester",MB_DEFBUTTON1);
    	case WM_PAINT:
    		glClear(GL_COLOR_BUFFER_BIT);
    		glBegin(GL_POLYGON);
    		glColor3f(1, 0, 0);
    		glVertex2f(-5, -5);
    		glVertex2f(-5, 5);
    		glColor3f(0, 0, 1);
    		glVertex2f(5, 5);
    		glVertex2f(5, -5);
    		glEnd();
    		glFlush();
    		break;
         case WM_DESTROY:
    		wglMakeCurrent( NULL, NULL );
    		wglDeleteContext( hRC );
    		::ReleaseDC( hwnd, hDC );
    		::PostQuitMessage (0);
            return 0; // return zero when processed
    If somebody can help me, I'l be happy.
    Thank you in advance!

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Dont rely on WM_PAINT for OpenGL......create a Render() function (or whatever), place your drawing code here and call it once in each messageloop......lookup NEHE over @ gamedev.net for ideas

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    How can I do that?
    This procedure is called while the window is creating and it will call this render() function before hDC ad hRC are ready and before call of the stuff in WM_CREATE at all.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    As I said - have a look at nehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. help with this
    By tyrantil in forum C Programming
    Replies: 18
    Last Post: 01-30-2005, 04:53 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM