Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

HemoGloben

Windows Class, OpenGL not compiling

This topic is 5269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you look at one of my other posts, you can see that I was trying to write a windows wrapper class. Well, I used my copy of OpenGL Game Programming, to throw together a windows class, and When I try to compile my test application, it doesn''t work. I get these errors: Main.cpp c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing '';'' before type ''void'' c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ''WINGDIAPI'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found Error executing cl.exe. Here''s the code:
#include <iostream>
#define WIN32_LEAN_AND_MEAN
#include <gl/glu.h>
#include <gl/gl.h>
#include <windows.h>


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	MSG msg;
	Window currentWind (400,400,10,10,hInstance,"Ben''s Test Application");
	currentWind.Create();

	bool done=false;

	while(!done)
	{
		PeekMessage(&msg, currentWind.getHWND(), NULL, NULL, PM_REMOVE);

		if(msg.message == WM_QUIT)
		{
			done=true;
		}
		else
		{
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glLoadIdentity();

			glColor3f(1.0f,0.0f,0.0f);
			glBegin(GL_TRIANGLES);
				glVertex3f(0.0f,0.0f,0.0f);
				glVertex3f(1.0f,0,0f,0.0f);
				glVertex3f(1.0f,1.0f,0.0f);
			glEnd();

			SwapBuffers(currentWind.getHDC());

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msh.wParam;
}
WindClass.h:
class Window
{
public:
	Window(int width1, int height1, int x, int y,HINSTANCE instance, char[] name)
	{
		width = width1;
		height = height1;
		xPos = x;
		yPos = y;
		AppName[] = name;
		hInstance = instance;
		Create();
	}
	
	HWND getHWND()
	{
		return hwnd;
	}

	HGLRC getHRC()
	{
		return hRC;
	}

	HDC getHDC()
	{
		return hDC;
	}


private:
	int width;
	int height;
	int xPos;
	int yPos;
	char AppName[];
	HGLRC hRC;
	HWND hwnd;
	HDC hDC;
	HINSTANCE hInstance;
	WNDCLASSEX windowClass;



	LRESULT CALLBACK WndProc(UINT message, WPARAM wParam, LPARAM lParam)
	{

		switch(message)
		{
		case WM_CREATE:
			hDC = GetDC(hwnd);
			SetupPixelFormat(hDC);

			hRC = wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);

			return 0;
			break;
		case WM_CLOSE:
			wglMakeCurrent(hDC, NULL);
			wglDeleteContext(hRC);

			PostQuitMessage(0);
			return 0;
			break;
		case WM_SIZE:
			height = HIWORD(lParam);
			width = LOWORD(lParam);

			if(height ==0)
			{
				height=1;
			}

			glViewport(0,0,width, height);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();

			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,1.0f,1000.0f);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			return 0;
			break;
		default:
			break;
		}
		return (DefWindowProc(hwnd, message,wParam,lParam));
	}



	int Create()
	{
		windowClass.cbSize			=sizeof(WNDCLASSEX);					
		windowClass.style			=CS_HREDRAW | CS_VREDRAW;
		windowClass.lpfnWndProc		=WndProc;
		windowClass.cbClsExtra		=0;
		windowClass.cbWndExtra		=0;
		windowClass.hInstance		=hInstance;
		windowClass.hIcon			=LoadIcon(NULL,IDI_APPLICATION);		//Default Icon

		windowClass.hCursor			=LoadCursor(NULL, IDC_APPLICATION);		//Default Arrow

		windowClass.hbrBackground	=NULL;									//Don''t need backround

		windowClass.lpszMenuName	=NULL;									//No Menu

		windowClass.lpszClassName	= "My Class";
		windowClass.hIconSm			=LoadIcon(NULL, IDI_WINLOGO);			//Small Icon


		if (!RegisterClassEx(&windowClass))
			return 0;

		hwnd = CreateWindowEx(NULL,
							  "My Class",
							  AppName,
							  WS_OVERLAPPEDWINDOW | WS_VISIBLE |
							  WS_SYSMENU | WS_CLIPCHILDREN |
							  WS_CLIPSIBLINGS,
							  xPos, yPos,
							  width, height,
							  NULL,
							  NULL,
							  hInstance,
							  NULL);

		if(hwnd)
			return 0;
		
		ShowWindow(hwnd,SW_SHOW);
		return 1;
	}

	void SetupPixelFormat()
	{
		int nPixelFormat;

		static PIXELFORMATDESCRIPTOR pfd = {
			sizeof(PIXELFORMATDESCRIPTOR),
				1,								//Version(always 1)

				PFD_DRAW_TO_WINDOW |			//Support Window

				PFD_SUPPORT_OPENGL |			//Support OpenGL

				PFD_DOUBLE_BUFFER |				//Support Double Buffering

				PFD_TYPE_RGBA,					//RGBA color mode

				32,								//32 bit Color mode

				0,0,0,0,0,0,					//Ignore color bits, not used

				0,								//no alpha Buffer

				0,								//ignore shift bit

				0,								//no accumulation buffer

				0,0,0,0,						//Ignore z accumulation bits

				16,								//16 bit z-Buffer size

				0,								//no stencil Buffer

				0,								//no Auxiliary Buffer

				PFD_MAIN_PLANE,					//Main drawing Plane

				0,								//reserved

				0,0,0};							//layerMasks ignored


			nPixelFormat = ChoosePixelFormat(hDC, &pfd);

			SetPixelFormat(hDC, nPixelFormat, &pfd);
	}
}
PS feel free to point out horrendous code, or errors, or anything for that matter. I need criticism anyway. (I''m uber noob)

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!