Nehe - WNDCLASS

Started by
8 comments, last by wsk 14 years, 1 month ago
Hi, i just wanted to get through the first lesson of NeHe's OpenGl Tutorials. I'm using DevCPP for that. http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01 i retyped the lesson to GLcreatWindow(...) and included the declaration of WndProc() where i was told to. now, when i'm trying to compile, i'm getting errors like "'struct WNDCLASS' has no member named 'obsClsExtra' ". Seems like it doesn't know where to find WNDCLASS, but i don't know either. Do i have to link a specific library? till now i've added "-lopengl32 -lglu32" to the linker.
Advertisement
A quick Google for WNDCLASS gives me this, which indicates to me that you misread or mistyped from the tutorial.

As a side note, you are getting a compile error. Compilation is a distinct stage from linking, so your library settings could not affect this. During linking, you get linker errors.
I've got that site too, and after having a break i've found the the typos :D

Anyway i'm getting a linker error ( [Linker error] undefined reference to `_Z7WndProcP6HWND__jjl@16' ).

That's why i thought about a missing lib.
Quote:Original post by wsk
i [...] included the declaration of WndProc() where i was told to.
Where did you put the definition of WndProc?

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by wsk
That's why i thought about a missing lib.
Nope, not a library issue. WndProc is a user-defined function not a library-defined anything. You didn't define WndProc (or didn't define it correctly).

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

First, grab a recent decent compiler. I don't know why beginners always ends up with Dev-C++. As most people recommend, you should grab Visual Studio 2008 Express Edition. Why?
http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/

Second, instead of typing manually NeHe code, why don't you just download the source file at the bottom of it's page? It won't contain typos like you had and will compile at first try.

Anyway, the only things you have to do usually to get this working is to include Windows.h, not any libs. The first error was with WNDCLASS, now it's with WndProc. It compile fine, so you have it's function prototype declared and referenced somewhere, but not it's function body since it have a problem in the linking stage.
Just the beginning of the code:

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

HGLRC hRC=NULL; // Permanent Rendering Context
HDC hDC=NULL; // Device Context->GDI (connects to Graphics Device Interface)
HWND hWnd=NULL; // Window Handler
HINSTANCE hInstance; // Program Instance

bool keys[256]; // monitoring keyboard
bool active=TRUE; // minimizing-> suspend program
bool fullscreen=TRUE; // Fullscreen-Mode?

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // CreateGLWindow() has reference to WndProc

...maybe i should get Visual Studio, to make sure it is my fault ;)
But i'm retyping the code from tutorial to remember it better. To copy code is quite inefficient for learning in my opinion.

thanks til now, i'll see if it runs properly in visual studio
Quote:
But i'm retyping the code from tutorial to remember it better. To copy code is quite inefficient for learning in my opinion.

I think you have confused memory retention for knowledge. The Win32 boilerplate for creating an OpenGL application is irrelevant. You can get copies from many free sources.

What is infinitely more important is to understand how this code affects your game. The depth buffer, matrix modes, pixel formats, double buffering (to name a small few)? All are given minimal explanation in this tutorial. Yes, its a beginner tutorial and sometimes you have to just give the user a black box to play with before they can bootstrap the learning process, but these are the areas you should concentrate your learning on.
Just as I said, you have the line:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

This is a function prototype (declaration), telling the compiler that you can reference it because you know the function definition (code body) exist somewhere. Problem is, you don't have it. If I look at NeHe lesson 1, the definition of WndProc is further down, just before WinMain()

LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window							UINT	uMsg,			// Message For This Window							WPARAM	wParam,			// Additional Message Information							LPARAM	lParam)			// Additional Message Information{	switch (uMsg)									// Check For Windows Messages	{		case WM_ACTIVATE:							// Watch For Window Activate Message		{			if (!HIWORD(wParam))					// Check Minimization State			{				active=TRUE;						// Program Is Active			}			else			{				active=FALSE;						// Program Is No Longer Active			}			return 0;								// Return To The Message Loop		}		case WM_SYSCOMMAND:							// Intercept System Commands		{			switch (wParam)							// Check System Calls			{				case SC_SCREENSAVE:					// Screensaver Trying To Start?				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?				return 0;							// Prevent From Happening			}			break;									// Exit		}		case WM_CLOSE:								// Did We Receive A Close Message?		{			PostQuitMessage(0);						// Send A Quit Message			return 0;								// Jump Back		}		case WM_KEYDOWN:							// Is A Key Being Held Down?		{			keys[wParam] = TRUE;					// If So, Mark It As TRUE			return 0;								// Jump Back		}		case WM_KEYUP:								// Has A Key Been Released?		{			keys[wParam] = FALSE;					// If So, Mark It As FALSE			return 0;								// Jump Back		}		case WM_SIZE:								// Resize The OpenGL Window		{			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height			return 0;								// Jump Back		}	}	// Pass All Unhandled Messages To DefWindowProc	return DefWindowProc(hWnd,uMsg,wParam,lParam);}


This have nothing to do with OpenGL though, this is basic C. You should probably learn the language a bit more before digging into 3D libraries.
I'm just doing this for university, otherwise i wouldn't use c for beginning with opengl ;)

So there was my fault, i thought WndProc was something that was only linked to. I tried to set up a Visual Studio Project myself and it worked. So no Problem til now anymore ;)

thank you all

This topic is closed to new replies.

Advertisement