Jump to content

  • Log In with Google      Sign In   
  • Create Account

Error creating dummy window for OpenGL 3.x Content


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 AndyEsser   GDNet+   -  Reputation: 386

Like
0Likes
Like

Posted 25 December 2013 - 05:53 AM

Hi all,

 

Trying to get my code to use an OpenGL 3.x Core Context. 

 

Previously my code has been working fine on Windows using just a 1.2 Context, but now that I've prototyped out the design I need to get a more recent context to do some of the more exciting things.

 

The issue I'm having is that my CreateWindow() call is return a null HWND, and GetLastError() is returning 0 - which is less than helpful!

 

Bit of background info. This code is called in a child thread of the main application thread (I've tried calling it in the main thread, with the same results) and there is already a Window that has been successfully created (but not created a GL Context yet).

 

Any thoughts what I might be doing wrong?

WNDCLASS wndClass;
HINSTANCE hInstance = 0;

ZeroMemory(&wndClass, sizeof(WNDCLASS));

wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;			
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WndProc;
wndClass.lpszClassName = TEXT("Dummy Window");
wndClass.lpszMenuName = 0;
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

DWORD err = GetLastError();
RegisterClass(&wndClass);
err = GetLastError();

HWND hWnd = CreateWindow(TEXT("Dummy Window"), "Dummy Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
err = GetLastError();
if (hWnd == NULL)
{
	return false;
}

return true;


Sponsor:

#2 AndyEsser   GDNet+   -  Reputation: 386

Like
0Likes
Like

Posted 25 December 2013 - 06:06 AM

Right, fixed this - I was being stupid.

 

In the WndProc method I was passing to Register class I was just returning 0 (as the method wouldn't be used). Changing that to 

 

static LRESULT CALLBACK WndProc(HWND hwnd, cxuint message, WPARAM wparam, LPARAM lparam)
{
return DefWindowProc(hwnd, message, wparam, lparam);
}
 
Worked perfectly...


#3 mark ds   Members   -  Reputation: 1291

Like
1Likes
Like

Posted 25 December 2013 - 07:59 AM

To save a bit of code,

 

wndClass.lpfnWndProc = (WNDPROC) DefWindowProc;

 

also works fine.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS