Like Tree1Likes
  • 1 Post By Fordy

OpenGL, problem creating rendering context

This is a discussion on OpenGL, problem creating rendering context within the C++ Programming forums, part of the General Programming Boards category; Hi all, I've been trying OpenGL for a few days now. I currently have a problem with my rendering context. ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    2

    Unhappy OpenGL, problem creating rendering context

    Hi all,

    I've been trying OpenGL for a few days now. I currently have a problem with my rendering context.

    I am following NeHe's tutorial at :
    NeHe Productions: Creating an OpenGL Window (Win32)

    I use the following header files and global variables :
    Code:
    #include "StdAfx.h"
    #include <gl/GL.h>
    #include <gl/GLU.h>
    #include <gl/GLAUX.h>
    #include <tchar.h>
    
    HGLRC	hRC=NULL;
    HDC		hDC=NULL;
    HWND	hWnd=NULL;
    HINSTANCE	hInstance;
    This is the part of the code that seem to be the problem, if it comes from the code at all.

    Code:
            if(!(hDC=GetDC(hWnd)))
    	{
    		KillGLWindow();			// Reset the display
    		MessageBox(NULL,_T("Can't create a GL Device Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;
    	} 
    
    
    
    	if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
    	{
    		KillGLWindow();
    		MessageBox(NULL,_T("Can't find a suitable pixelformat."), _T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;
    	}
    
    
    	if(!(hRC=wglCreateContext(hDC)))
    	{
    		KillGLWindow();
    		MessageBox(NULL,_T("Can't Create a GL Rendering Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;
    	}
    
    
    	if(!wglMakeCurrent(hDC,hRC))
    	{
    		KillGLWindow();
    		MessageBox(NULL,_T("Can't Activate the GL Rendering Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;
    	}
    I get the "Can't Create a GL Rendering Context." message box...

    Any clue?

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403
    This may seem daft question but are you certain your system includes openGL? Are you using an IDE? If so have you tried using the default openGL project template? which should create a context for you if supported, so you can at least eliminate that issue, you should post some more of your code also
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    You seem to have missed a step, namely SetPixelFormat(hDC,PixelFormat,&pfd)

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    2
    -_- what a shame, Can't even follow a tuto correctly... This is what happen when you learn overnight.

    Thank you soo much Fordy, I was missing this one line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. openGL rendering
    By zacs7 in forum Game Programming
    Replies: 11
    Last Post: 10-24-2007, 03:58 PM
  2. OpenGL rendering problem
    By JJFMJR in forum Game Programming
    Replies: 8
    Last Post: 08-31-2007, 07:26 PM
  3. Device & Rendering Context
    By hannibar in forum Windows Programming
    Replies: 1
    Last Post: 12-16-2005, 04:28 AM
  4. Not drawing to rendering context...
    By EvBladeRunnervE in forum Game Programming
    Replies: 5
    Last Post: 12-05-2003, 08:39 PM
  5. Creating Context Menus
    By Okiesmokie in forum Windows Programming
    Replies: 1
    Last Post: 04-25-2002, 04:21 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21