Advertisement

Help with Creating GL Window...

Started by January 14, 2003 04:40 PM
8 comments, last by Sky 22 years, 1 month ago
Dev-C++ Seems to be working, and now I've written the code for creating a GL Window in Windows, and I fixed all the errors but one... [Linker Error] undefined refrence to 'gluPerspective@32' I can't figure out what's wrong now. (and all the libraries seem to be including properly and everything...) Here's the code up to the gluPerspective
        
#include <windows.h>								// Header File For Windows
#include <gl\gl.h>								    // Header File For The OpenGL32 Library
#include <gl\glu.h>							    	// Header File For The GLu32 Library
#include <gl\glaux.h>								// Header File For The GLaux Library



HGLRC           hRC=NULL;							// Permanent Rendering Context

HDC             hDC=NULL;							// Private GDI Device Context

HWND            hWnd=NULL;							// Holds Our Window Handle

HINSTANCE       hInstance;							// Holds The Instance Of The Application


bool keys[256];								// Array Used For The Keyboard Routine

bool active=TRUE;								// Window Active Flag Set To TRUE By Default

bool fullscreen=TRUE;							// Fullscreen Flag Set To Fullscreen Mode By Default


LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);				// Declaration For WndProc


GLvoid ReSizeGLScene(GLsizei width, GLsizei height) {	// Resize And Initialize The GL Window

  if (height==0)						                // Prevent A Divide By Zero By

      height=1;						                // Making Height Equal One

	
  glViewport(0, 0, width, height);			      	// Reset The Current Viewport

	
// Perspective Stuff -------------------------------

  glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix

  glLoadIdentity();						        	// Reset The Projection Matrix


  // Calculate The Aspect Ratio Of The Window

  gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

  glMatrixMode(GL_MODELVIEW);					// Select The Modelview Matrix

  glLoadIdentity();							// Reset The Modelview Matrix

}
          
I tried to compile the NeheGL Basecode but I got the same exact error. [edited by - Sky on January 14, 2003 5:46:20 PM] [edited by - Sky on January 14, 2003 5:55:41 PM]
It doesn''t seem to be linking the gluax.h library... It didn''t have it before so I just copied it from MSVC++ to the gl folder of Dev-C++.... Is there a differen''t library I should use instead? Or how do i make it work? and i searched on google and it said that gluax isn''t used much anymore and you''re better off using glut... does glut have the same functions? or would i have to translate the nehe tutorials into glut functions? ::So confused::
Advertisement
#include <gl/glu.h>

usually...
edit Newbie unfriendly contents removed.

The file that's missing is glu32.lib, or libglu32.a for Dev-C++. Simply go to Project->Project Options->"Linker Options...or Object Files", and add "-lglu32"

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on January 14, 2003 7:11:02 PM]

[twitter]warrenm[/twitter]

quote:
Original post by ZealousElixir
edit Newbie unfriendly contents removed.



lol... I pressed quote before you removed them, but it quoted your edit instead

anyways, kinda hostile sounding comments that you deleted, but thanks anyways. It works now ^.^

Yeah, had a bad day at work Glad you caught the edit though, and sorry if I was a little harsh before.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

Advertisement
That''s ok, I''m just glad I found out what was wrong... unfortunatly now I have even more -.-;;;

Ok, there''s the whole thing. It compiles fine, but when I run it it doesn''t clear the window (you can see right through it to the desktop below) the square and triangle aren''t drawing.

Also when I close the program it gives me the "Releae of DC and RC Failed." message...


  #include <windows.h>								// Header File For Windows#include <gl\gl.h>								    // Header File For The OpenGL32 Library#include <gl\glu.h>							    	// Header File For The GLu32 Library#include <gl\glaux.h>								// Header File For The GLaux LibraryHGLRC           hRC=NULL;							// Permanent Rendering ContextHDC             hDC=NULL;							// Private GDI Device ContextHWND            hWnd=NULL;							// Holds Our Window HandleHINSTANCE       hInstance;							// Holds The Instance Of The Applicationbool keys[256];								// Array Used For The Keyboard Routinebool active=TRUE;								// Window Active Flag Set To TRUE By Defaultbool fullscreen=TRUE;							// Fullscreen Flag Set To Fullscreen Mode By DefaultLRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);				// Declaration For WndProcGLvoid ReSizeGLScene(GLsizei width, GLsizei height) {	// Resize And Initialize The GL Window  if (height==0)						                // Prevent A Divide By Zero By      height=1;						                // Making Height Equal One	  glViewport(0, 0, width, height);			      	// Reset The Current Viewport	// Perspective Stuff -------------------------------  glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix  glLoadIdentity();						        	// Reset The Projection Matrix  // Calculate The Aspect Ratio Of The Window  gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);  glMatrixMode(GL_MODELVIEW);					// Select The Modelview Matrix  glLoadIdentity();				    			// Reset The Modelview Matrix}int InitGL(GLvoid) {  glShadeModel(GL_SMOOTH);  //Smooth Shading  glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black Background    glClearDepth(1.0f); //Depth Buffer Setrup  glEnable(GL_DEPTH_TEST); //Depth testing  glDepthFunc(GL_LEQUAL); //Type of testing to do    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Best Perspective Calculations    return TRUE;}// Where I draw the Scene...int DrawGLScene(GLvoid) {   //Drawing Stuff  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear Screen adn Depth Buffer  glLoadIdentity(); // Reset Modelview Matrix    glTranslatef(-1.5f,0.0f,-6.0f);  glBegin(GL_TRIANGLES);    glVertex3f(0.0f,1.0f,0.0f);    glVertex3f(-1.0f,-1.0f,0.0f);    glVertex3f(1.0f,-1.0f,0.0f);  glEnd();    glTranslatef(3.0f,0.0f,0.0f);  glBegin(GL_QUADS);    glVertex3f(-1.0f,1.0f,0.0f);    glVertex3f(1.0f,1.0f,0.0f);    glVertex3f(1.0f,-1.0f,0.0f);    glVertex3f(-1.0f,-1.0f,0.0f);  glEnd();    return TRUE;}GLvoid KillGLWindow(GLvoid) { //Properly Kill the GL Window  if (fullscreen) {    ChangeDisplaySettings(NULL,0); //Switch back to Desktop    ShowCursor(TRUE);  }    if (hRC) {    if (!wglMakeCurrent(NULL,NULL)) //Release DC and RC      MessageBox(NULL,"Releae of DC and RC Failed.","SHUDOWN ERROR",MB_OK | MB_ICONINFORMATION);    if (!wglDeleteContext(hRC))  //Release RC      MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);    hRC=NULL;  }    if (hDC && !ReleaseDC(hWnd,hDC)) { //Release DC    MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);    hDC=NULL;  }      if (hWnd && !DestroyWindow(hWnd)) {//Destroy Window    MessageBox(NULL,"Could Not Release hWnd","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);    hInstance=NULL;  } }  BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) {  GLuint PixelFormat;  WNDCLASS wc;     //Window Class Structure  DWORD dwExStyle, //Window Extended Style        dwStyle;   //Window Style         RECT WindowRect; //Create Rectangle Window...  WindowRect.left=(long)0;        //Left Side, 0  WindowRect.right=(long)width;   //Right Side, width  WindowRect.top=(long)0;         //Top, 0  WindowRect.bottom=(long)height; //Bottom, height     fullscreen=fullscreenflag; //Set Global Flag    hInstance = GetModuleHandle(NULL);  wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;  wc.lpfnWndProc = (WNDPROC) WndProc;  wc.cbClsExtra = 0;   wc.cbWndExtra = 0;  wc.hInstance = hInstance;  wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);  wc.hCursor = LoadCursor(NULL, IDC_ARROW);  wc.hbrBackground = NULL;  wc.lpszMenuName = NULL;  wc.lpszClassName = "OpenGL";    if (!RegisterClass(&wc)) {    MessageBox(NULL,"Failed to Register the Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }    if (fullscreen) {    DEVMODE dmScreenSettings; //Device Mode    memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); //Clear Memory    dmScreenSettings.dmSize = sizeof(dmScreenSettings);    dmScreenSettings.dmPelsWidth = width;    dmScreenSettings.dmPelsHeight = height;    dmScreenSettings.dmBitsPerPel = bits;    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;        //CDS_FULLSCREEN gets rid of start bar    if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN) !=DISP_CHANGE_SUCCESSFUL) {      // If The Mode Fails, Offer Two Options.  Quit Or Run In A Window.      if (MessageBox(NULL,        "The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?",          "Nehe GL", MB_YESNO|MB_ICONEXCLAMATION)==IDYES) {            fullscreen = FALSE;      } else {        MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);        return FALSE;      }    }  }  if (fullscreen) {    dwExStyle = WS_EX_APPWINDOW;    dwStyle = WS_POPUP;    ShowCursor(FALSE);  } else {    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;    dwStyle = WS_OVERLAPPEDWINDOW;  }  AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);         if (!(hWnd=CreateWindowEx( dwExStyle,                                 "OpenGL",                                 title,                                 WS_CLIPSIBLINGS |                                 WS_CLIPCHILDREN |                                 dwStyle,                                 0,0,                                WindowRect.right-WindowRect.left,                                WindowRect.bottom-WindowRect.top,                                NULL, //No Parent Window                                NULL, //No Menu                                hInstance,                                NULL))) //Don''t Pass anything to WM_CREATE       {         KillGLWindow(); //Reset Display         MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);         return FALSE;      }    //TIRED OF TYPING NOW!        static	PIXELFORMATDESCRIPTOR pfd=					// pfd Tells Windows How We Want Things To Be	  {    	sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor		1,								// Version Number		PFD_DRAW_TO_WINDOW |						// Format Must Support Window		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL		PFD_DOUBLEBUFFER,						// Must Support Double Buffering		PFD_TYPE_RGBA,							// Request An RGBA Format		bits,								// Select Our Color Depth		0, 0, 0, 0, 0, 0,						// Color Bits Ignored		0,								// No Alpha Buffer		0,								// Shift Bit Ignored		0,								// No Accumulation Buffer		0, 0, 0, 0,							// Accumulation Bits Ignored		16,								// 16Bit Z-Buffer (Depth Buffer)		0,								// No Stencil Buffer		0,								// No Auxiliary Buffer		PFD_MAIN_PLANE,							// Main Drawing Layer		0,								// Reserved		0, 0, 0								// Layer Masks Ignored	};        if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?	{		KillGLWindow();							// Reset The Display		MessageBox(NULL,"Can''t Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;							// Return FALSE	}     if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {      KillGLWindow();      MessageBox(NULL,"Can''t Find a Suitable PixelFormat.","Error",MB_OK | MB_ICONEXCLAMATION);      return FALSE;    }        if(!SetPixelFormat(hDC,PixelFormat,&pfd))				// Are We Able To Set The Pixel Format?	{		KillGLWindow();							// Reset The Display		MessageBox(NULL,"Can''t Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;							// Return FALSE	}  	if (!(hRC=wglCreateContext(hDC)))					// Are We Able To Get A Rendering Context?	{		KillGLWindow();							// Reset The Display		MessageBox(NULL,"Can''t Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;							// Return FALSE	}	ShowWindow(hWnd,SW_SHOW);						// Show The Window	SetForegroundWindow(hWnd);						// Slightly Higher Priority	SetFocus(hWnd);								// Sets Keyboard Focus To The Window	ReSizeGLScene(width, height);						// Set Up Our Perspective GL Screen	if (!InitGL())								// Initialize Our Newly Created GL Window	{		KillGLWindow();							// Reset The Display		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;							// Return FALSE    }      return TRUE;}  LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  switch (uMsg) {    case WM_ACTIVATE: {  //Watch for Window Activate Message     if (!HIWORD(wParam)) //Check Minimization State       active = TRUE;     else        active = FALSE;      return 0;    }    case WM_SYSCOMMAND: {//Intercept System Commands      switch (wParam) {        case SC_SCREENSAVE: // Screensaver?        case SC_MONITORPOWER: // Monitor going to Powersave?        return 0; //prevent from happening      }      break;    }    case WM_CLOSE: {            PostQuitMessage(0); //Send Quit Message      return 0;    }    case WM_KEYDOWN: {      keys[wParam] = 1;      return 0;    }    case WM_KEYUP: {      keys[wParam] = FALSE;      return 0;    }    case WM_SIZE: {      //Resize Window      ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); //LoWord = Width hiword = height      return 0;    }  }    return DefWindowProc(hWnd,uMsg,wParam,lParam);}// Windows Main Function thing int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) {  MSG msg;  BOOL done=0;    if (MessageBox(NULL,"Would You Like to Run in Fullscreen Mode?","Start Fullscreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)       fullscreen=false;    if (!CreateGLWindow("Sky''s Box",640,480,16,fullscreen))       return 0;          while (!done) {    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {      if (msg.message==WM_QUIT) {        done = 1;      } else {        TranslateMessage(&msg);        DispatchMessage(&msg);      }    } else {      if (active) {        if (keys[VK_ESCAPE]) {          done = 1;        } else {          DrawGLScene();          SwapBuffers(hDC);        }      }            if (keys[VK_F1]) {        keys[VK_F1]=FALSE;        KillGLWindow();        fullscreen=!fullscreen;        if (!CreateGLWindow("Sky''s Box",800,600,16,fullscreen))           return 0;        }    }  }  KillGLWindow();  return (msg.wParam);}  


I can''t see any initial call to wglMakeCurrent

Woops... Missed that. ::adds it::

Thankyou, it works now. ^.^

(MY FIRST GL SCENE WOOHOO!)
You also use Dev-C++? Cool. Don''t forget to add -lglaux for the compiler. Soon you won''t it on later tutorial.

This topic is closed to new replies.

Advertisement