Can somebody help me, I wish to learn OpenGL and I don't understand how to set it up. I am using a windows XP machine with Code::Blocks 8.2 and MingGW. How do I get OpenGL working?
Labdabeta 182 Posting Pro in Training Featured Poster
To elaborate (since I am very anxious) I am using NeHe's tutorials and my results for tutorial 1 on windows was a list of errors:
D:\Programming\C++\OPENGLTEST\test1.cpp||In function `GLvoid ReSizeGLScene(GLsizei, GLsizei)':|
D:\Programming\C++\OPENGLTEST\test1.cpp|14|error: `glViewPort' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|14|warning: unused variable 'glViewPort'|
D:\Programming\C++\OPENGLTEST\test1.cpp||In function `int InitGL()':|
D:\Programming\C++\OPENGLTEST\test1.cpp|25|error: `glClearColour' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|25|warning: unused variable 'glClearColour'|
D:\Programming\C++\OPENGLTEST\test1.cpp||In function `BOOL CreateGLWindow(char*, int, int, int, bool)':|
D:\Programming\C++\OPENGLTEST\test1.cpp|104|error: `bits' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|108|error: `MD_YESNO' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|108|warning: unused variable 'MD_YESNO'|
D:\Programming\C++\OPENGLTEST\test1.cpp|104|warning: unused variable 'bits'|
D:\Programming\C++\OPENGLTEST\test1.cpp|126|error: `dxStype' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|126|warning: unused variable 'dxStype'|
D:\Programming\C++\OPENGLTEST\test1.cpp|129|error: invalid conversion from `long int' to `HWND__*'|
..\..\CodeBlocks\MinGW\include\winuser.h|3472|error: too many arguments to function `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'|
D:\Programming\C++\OPENGLTEST\test1.cpp|129|error: at this point in file|
D:\Programming\C++\OPENGLTEST\test1.cpp|143|error: `bits' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|143|warning: unused variable 'bits'|
D:\Programming\C++\OPENGLTEST\test1.cpp||In function `LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
D:\Programming\C++\OPENGLTEST\test1.cpp|223|error: `umsh' was not declared in this scope|
D:\Programming\C++\OPENGLTEST\test1.cpp|223|warning: unused variable 'umsh'|
||=== Build finished: 10 errors, 7 warnings ===|
My source code is:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\GLAUX.h>
HGLRC hRC=NULL;
HDC hDC=NULL;
HWND hwnd=NULL;
HINSTANCE hInstance;
bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
GLvoid ReSizeGLScene(GLsizei width,GLsizei height)
{
if (height==0)
height=1;
glViewPort(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Viewing angle,aspect ratio,closest drawable,farthest drawable
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
};
int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColour(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return TRUE;
}
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
return TRUE;
};
GLvoid KillGLWindow(GLvoid)
{
if (fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if (hRC)
{
if (!wglMakeCurrent(NULL,NULL))
MessageBox(NULL,"Release of DC and RC failed","Fatal Error",MB_OK|MB_ICONINFORMATION);
if (!wglDeleteContext(hRC))
MessageBox(NULL,"Release of RC failed","Fatal Error",MB_OK|MB_ICONINFORMATION);
hRC=NULL;
}
if (hDC&&!ReleaseDC(hwnd,hDC))
{
MessageBox(NULL,"Release of DC failed","Fatal Error",MB_OK|MB_ICONINFORMATION);
hDC=NULL;
}
if (hwnd&&!DestroyWindow(hwnd))
{
MessageBox(NULL,"Release of window failed","Fatal Error",MB_OK|MB_ICONINFORMATION);
hwnd=NULL;
}
if (!UnregisterClass("OpenGL",hInstance))
{
MessageBox(NULL,"Could not unregister class","Fatal Error",MB_OK|MB_ICONINFORMATION);
hInstance=NULL;
}
}
BOOL CreateGLWindow(char *title,int width,int height,int bpp,bool fscreen)
{
GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
fullscreen=fscreen;
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 Test";
if (!RegisterClass(&wc))
{
MessageBox(NULL,"Failed to register the window class","Fatal Error",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth=width;
dmScreenSettings.dmPelsHeight=height;
dmScreenSettings.dmBitsPerPel=bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL,"Fullscreen doesn't work on your computer, can a window be used instead?","OpenGL Test",MD_YESNO|MB_ICONEXCLAMATION)==IDYES)
fullscreen=false;
else
{
MessageBox(NULL,"Program is closeing","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;
dxStype=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
if (!(hwnd=CreateWindowEx(dwExStyle,"OpenGL Test",title,WS_CLIPSIBLINGS|WS_CLIPCHILDREN,dwStyle,0,0,WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,NULL,NULL,hInstance,NULL)))
{
KillGLWindow();
MessageBox(NULL,"Window Creation Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
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)))
{
KillGLWindow();
MessageBox(NULL,"Cannot create DC","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
KillGLWindow();
MessageBox(NULL,"Cannot find a Pixel Format","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!SetPixelFormat(hDC,PixelFormat,&pfd))
{
KillGLWindow();
MessageBox(NULL,"Cannot set the Pixel Format","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(hRC=wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"Cannot create a GL context","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
ShowWindow(hwnd,SW_SHOW);
SetForegroundWindow(hwnd);
SetFocus(hwnd);
ReSizeGLScene(width,height);
if (!InitGL())
{
KillGLWindow();
MessageBox(NULL,"Initialization failed","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)
{
switch (umsg)
{
case WM_ACTIVATE:
if (!HIWORD(wparam))
active=TRUE;
else
active=FALSE;
return 0;
case WM_SYSCOMMAND:
switch (wparam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
keys[wparam]=TRUE;
return 0;
case WM_KEYUP:
keys[wparam]=FALSE;
return 0;
case WM_SIZE:
ReSizeGLScene(LOWORD(lparam),HIWORD(lparam));
return 0;
}
return DefWindowProc(hwnd,umsh,wparam,lparam);
}
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int ncmdshow)
{
MSG msg;
BOOL done=FALSE;
fullscreen=MessageBox(NULL,"Fullscreen Mode?","Start Fullscreen?",MB_YESNO|MB_ICONQUESTION)==IDNO;
if (!CreateGLWindow("TEST",640,480,16,fullscreen))
return 0;
while (!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
done=TRUE;
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if (active)
{
if (keys[VK_ESCAPE])
done=TRUE;
else
{
DrawGLScene();
SwapBuffers(hDC);
}
}
if (keys[VK_F1])
{
keys[VK_F1]=FALSE;
KillGLWindow();
fullscreen=!fullscreen;
if (!CreateGLWindow("TEST",640,480,16,fullscreen))
return 0;
}
}
}
KillGLWindow();
return (msg.wParam);
}
I originally did not have glaux.h so I added it in:
/*++ BUILD Version: 0004 // Increment this if a change has global effects
Copyright (c) 1985-95, Microsoft Corporation
Module Name:
glaux.h
Abstract:
Procedure declarations, constant definitions and macros for the OpenGL
Auxiliary Library.
--*/
#ifndef __GLAUX_H__
#define __GLAUX_H__
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
** ToolKit Window Types
** In the future, AUX_RGBA may be a combination of both RGB and ALPHA
*/
#define AUX_RGB 0
#define AUX_RGBA AUX_RGB
#define AUX_INDEX 1
#define AUX_SINGLE 0
#define AUX_DOUBLE 2
#define AUX_DIRECT 0
#define AUX_INDIRECT 4
#define AUX_ACCUM 8
#define AUX_ALPHA 16
#define AUX_DEPTH24 32 /* 24-bit depth buffer */
#define AUX_STENCIL 64
#define AUX_AUX 128
#define AUX_DEPTH16 256 /* 16-bit depth buffer */
#define AUX_FIXED_332_PAL 512
#define AUX_DEPTH AUX_DEPTH16 /* default is 16-bit depth buffer */
/*
** Window Masks
*/
#define AUX_WIND_IS_RGB(x) (((x) & AUX_INDEX) == 0)
#define AUX_WIND_IS_INDEX(x) (((x) & AUX_INDEX) != 0)
#define AUX_WIND_IS_SINGLE(x) (((x) & AUX_DOUBLE) == 0)
#define AUX_WIND_IS_DOUBLE(x) (((x) & AUX_DOUBLE) != 0)
#define AUX_WIND_IS_INDIRECT(x) (((x) & AUX_INDIRECT) != 0)
#define AUX_WIND_IS_DIRECT(x) (((x) & AUX_INDIRECT) == 0)
#define AUX_WIND_HAS_ACCUM(x) (((x) & AUX_ACCUM) != 0)
#define AUX_WIND_HAS_ALPHA(x) (((x) & AUX_ALPHA) != 0)
#define AUX_WIND_HAS_DEPTH(x) (((x) & (AUX_DEPTH24 | AUX_DEPTH16)) != 0)
#define AUX_WIND_HAS_STENCIL(x) (((x) & AUX_STENCIL) != 0)
#define AUX_WIND_USES_FIXED_332_PAL(x) (((x) & AUX_FIXED_332_PAL) != 0)
/*
** ToolKit Event Structure
*/
typedef struct _AUX_EVENTREC {
GLint event;
GLint data[4];
} AUX_EVENTREC;
/*
** ToolKit Event Types
*/
#define AUX_EXPOSE 1
#define AUX_CONFIG 2
#define AUX_DRAW 4
#define AUX_KEYEVENT 8
#define AUX_MOUSEDOWN 16
#define AUX_MOUSEUP 32
#define AUX_MOUSELOC 64
/*
** Toolkit Event Data Indices
*/
#define AUX_WINDOWX 0
#define AUX_WINDOWY 1
#define AUX_MOUSEX 0
#define AUX_MOUSEY 1
#define AUX_MOUSESTATUS 3
#define AUX_KEY 0
#define AUX_KEYSTATUS 1
/*
** ToolKit Event Status Messages
*/
#define AUX_LEFTBUTTON 1
#define AUX_RIGHTBUTTON 2
#define AUX_MIDDLEBUTTON 4
#define AUX_SHIFT 1
#define AUX_CONTROL 2
/*
** ToolKit Key Codes
*/
#define AUX_RETURN 0x0D
#define AUX_ESCAPE 0x1B
#define AUX_SPACE 0x20
#define AUX_LEFT 0x25
#define AUX_UP 0x26
#define AUX_RIGHT 0x27
#define AUX_DOWN 0x28
#define AUX_A 'A'
#define AUX_B 'B'
#define AUX_C 'C'
#define AUX_D 'D'
#define AUX_E 'E'
#define AUX_F 'F'
#define AUX_G 'G'
#define AUX_H 'H'
#define AUX_I 'I'
#define AUX_J 'J'
#define AUX_K 'K'
#define AUX_L 'L'
#define AUX_M 'M'
#define AUX_N 'N'
#define AUX_O 'O'
#define AUX_P 'P'
#define AUX_Q 'Q'
#define AUX_R 'R'
#define AUX_S 'S'
#define AUX_T 'T'
#define AUX_U 'U'
#define AUX_V 'V'
#define AUX_W 'W'
#define AUX_X 'X'
#define AUX_Y 'Y'
#define AUX_Z 'Z'
#define AUX_a 'a'
#define AUX_b 'b'
#define AUX_c 'c'
#define AUX_d 'd'
#define AUX_e 'e'
#define AUX_f 'f'
#define AUX_g 'g'
#define AUX_h 'h'
#define AUX_i 'i'
#define AUX_j 'j'
#define AUX_k 'k'
#define AUX_l 'l'
#define AUX_m 'm'
#define AUX_n 'n'
#define AUX_o 'o'
#define AUX_p 'p'
#define AUX_q 'q'
#define AUX_r 'r'
#define AUX_s 's'
#define AUX_t 't'
#define AUX_u 'u'
#define AUX_v 'v'
#define AUX_w 'w'
#define AUX_x 'x'
#define AUX_y 'y'
#define AUX_z 'z'
#define AUX_0 '0'
#define AUX_1 '1'
#define AUX_2 '2'
#define AUX_3 '3'
#define AUX_4 '4'
#define AUX_5 '5'
#define AUX_6 '6'
#define AUX_7 '7'
#define AUX_8 '8'
#define AUX_9 '9'
/*
** ToolKit Gets and Sets
*/
#define AUX_FD 1 /* return fd (long) */
#define AUX_COLORMAP 3 /* pass buf of r, g and b (unsigned char) */
#define AUX_GREYSCALEMAP 4
#define AUX_FOGMAP 5 /* pass fog and color bits (long) */
#define AUX_ONECOLOR 6 /* pass index, r, g, and b (long) */
/*
** Color Macros
*/
#define AUX_BLACK 0
#define AUX_RED 13
#define AUX_GREEN 14
#define AUX_YELLOW 15
#define AUX_BLUE 16
#define AUX_MAGENTA 17
#define AUX_CYAN 18
#define AUX_WHITE 19
extern float auxRGBMap[20][3];
#define AUX_SETCOLOR(x, y) (AUX_WIND_IS_RGB((x)) ? \
glColor3fv(auxRGBMap[(y)]) : glIndexf((y)))
/*
** RGB Image Structure
*/
typedef struct _AUX_RGBImageRec {
GLint sizeX, sizeY;
unsigned char *data;
} AUX_RGBImageRec;
/*
** Prototypes
*/
void APIENTRY auxInitDisplayMode(GLenum);
void APIENTRY auxInitPosition(int, int, int, int);
/* GLenum APIENTRY auxInitWindow(LPCTSTR); */
#ifdef UNICODE
#define auxInitWindow auxInitWindowW
#else
#define auxInitWindow auxInitWindowA
#endif
GLenum APIENTRY auxInitWindowA(LPCSTR);
GLenum APIENTRY auxInitWindowW(LPCWSTR);
void APIENTRY auxCloseWindow(void);
void APIENTRY auxQuit(void);
void APIENTRY auxSwapBuffers(void);
typedef void (CALLBACK* AUXMAINPROC)(void);
void APIENTRY auxMainLoop(AUXMAINPROC);
typedef void (CALLBACK* AUXEXPOSEPROC)(int, int);
void APIENTRY auxExposeFunc(AUXEXPOSEPROC);
typedef void (CALLBACK* AUXRESHAPEPROC)(GLsizei, GLsizei);
void APIENTRY auxReshapeFunc(AUXRESHAPEPROC);
typedef void (CALLBACK* AUXIDLEPROC)(void);
void APIENTRY auxIdleFunc(AUXIDLEPROC);
typedef void (CALLBACK* AUXKEYPROC)(void);
void APIENTRY auxKeyFunc(int, AUXKEYPROC);
typedef void (CALLBACK* AUXMOUSEPROC)(AUX_EVENTREC *);
void APIENTRY auxMouseFunc(int, int, AUXMOUSEPROC);
int APIENTRY auxGetColorMapSize(void);
void APIENTRY auxGetMouseLoc(int *, int *);
void APIENTRY auxSetOneColor(int, float, float, float);
void APIENTRY auxSetFogRamp(int, int);
void APIENTRY auxSetGreyRamp(void);
void APIENTRY auxSetRGBMap(int, float *);
/* AUX_RGBImageRec * APIENTRY auxRGBImageLoad(LPCTSTR); */
#ifdef UNICODE
#define auxRGBImageLoad auxRGBImageLoadW
#else
#define auxRGBImageLoad auxRGBImageLoadA
#endif
AUX_RGBImageRec * APIENTRY auxRGBImageLoadA(LPCSTR);
AUX_RGBImageRec * APIENTRY auxRGBImageLoadW(LPCWSTR);
#ifdef UNICODE
#define auxDIBImageLoad auxDIBImageLoadW
#else
#define auxDIBImageLoad auxDIBImageLoadA
#endif
AUX_RGBImageRec * APIENTRY auxDIBImageLoadA(LPCSTR);
AUX_RGBImageRec * APIENTRY auxDIBImageLoadW(LPCWSTR);
void APIENTRY auxCreateFont(void);
/* void APIENTRY auxDrawStr(LPCTSTR); */
#ifdef UNICODE
#define auxDrawStr auxDrawStrW
#else
#define auxDrawStr auxDrawStrA
#endif
void APIENTRY auxDrawStrA(LPCSTR);
void APIENTRY auxDrawStrW(LPCWSTR);
void APIENTRY auxWireSphere(GLdouble);
void APIENTRY auxSolidSphere(GLdouble);
void APIENTRY auxWireCube(GLdouble);
void APIENTRY auxSolidCube(GLdouble);
void APIENTRY auxWireBox(GLdouble, GLdouble, GLdouble);
void APIENTRY auxSolidBox(GLdouble, GLdouble, GLdouble);
void APIENTRY auxWireTorus(GLdouble, GLdouble);
void APIENTRY auxSolidTorus(GLdouble, GLdouble);
void APIENTRY auxWireCylinder(GLdouble, GLdouble);
void APIENTRY auxSolidCylinder(GLdouble, GLdouble);
void APIENTRY auxWireIcosahedron(GLdouble);
void APIENTRY auxSolidIcosahedron(GLdouble);
void APIENTRY auxWireOctahedron(GLdouble);
void APIENTRY auxSolidOctahedron(GLdouble);
void APIENTRY auxWireTetrahedron(GLdouble);
void APIENTRY auxSolidTetrahedron(GLdouble);
void APIENTRY auxWireDodecahedron(GLdouble);
void APIENTRY auxSolidDodecahedron(GLdouble);
void APIENTRY auxWireCone(GLdouble, GLdouble);
void APIENTRY auxSolidCone(GLdouble, GLdouble);
void APIENTRY auxWireTeapot(GLdouble);
void APIENTRY auxSolidTeapot(GLdouble);
/*
** Window specific functions
** hwnd, hdc, and hglrc valid after auxInitWindow()
*/
HWND APIENTRY auxGetHWND(void);
HDC APIENTRY auxGetHDC(void);
HGLRC APIENTRY auxGetHGLRC(void);
/*
** Viewperf support functions and constants
*/
/* Display Mode Selection Criteria */
enum {
AUX_USE_ID = 1,
AUX_EXACT_MATCH,
AUX_MINIMUM_CRITERIA
};
void APIENTRY auxInitDisplayModePolicy(GLenum);
GLenum APIENTRY auxInitDisplayModeID(GLint);
GLenum APIENTRY auxGetDisplayModePolicy(void);
GLint APIENTRY auxGetDisplayModeID(void);
GLenum APIENTRY auxGetDisplayMode(void);
#ifdef __cplusplus
}
#endif
#endif /* __GLAUX_H__ */
I have also linked all of my libraries correctly (as far as I can tell). Why am I getting errors?!
nezachem 616 Practically a Posting Shark
You really need to check your spelling. It is glVewport, glClearColor, umsg, etc.
Labdabeta 182 Posting Pro in Training Featured Poster
Wow, I cna't spell. Anyways, I ran it and it still didn't really work. The sequence of events/messages was:
Fullscreen? NO
A transparent window appears.
Hit 'X'
Release of DC and RC failed
Could not unregister class
Why did I get the errors?
Labdabeta 182 Posting Pro in Training Featured Poster
I really need this test program to work. All it does is show an empty window (transparent contents) and when you exit it says "Release of Device Context and Rendering Context failed." Here is the code:
3dH.h:
#ifndef h3dH_H
#define h3dH_H
#include <windows.h>
#include <windowsx.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\GLAUX.h>
#define ERR(X,Y) MessageBox(NULL,Y,X,MB_OK|MB_ICONEXCLAMATION)
#define QUESTION(X,Y) MessageBox(NULL,Y,X,MB_YESNO|MB_ICONEXCLAMATION)
#define MESSAGE(X) PeekMessage(&X,NULL,0,0,PM_REMOVE)
typedef void(*DrawFunc)(int *);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
bool KEY[256];
int mouse_x;
int mouse_y;
int deltascroll;
bool active;
bool fullscreen;
HDC hDC;
HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
char *classname;
void SetMousePos(int x, int y);
void Resize(int w, int h);
void Resize(int w, int h, double vangle);
void Resize(int w, int h, double vnear, double vfar);
void Resize(int w, int h, double vangle, double vnear, double vfar);
int Init();
int Draw();
int Draw(DrawFunc draw);
void Step();
void Kill();
int Create(char *title, int width, int height, int bpp, bool fscreen);
int Create(char *title, int width, int height, int bpp, bool fscreen, int posx, int posy);
int Create(char *title, int width, int height, int bpp, bool fscreen, char *cname);
int Create(char *title, int width, int height, int bpp, bool fscreen, int posx, int posy, char *cname);
void SetMousePos(int x, int y)
{
SetCursorPos(x,y);
POINT mpos;
GetCursorPos(&mpos);
mouse_x=mpos.x;
mouse_y=mpos.y;
}
void Resize(int width, int height, double vangle, double vnear, double vfar)
{
if (height==0)
height=1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(vangle,(float)width/(float)height,vnear,vfar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Resize(int width, int height, double vnear, double vfar)
{
Resize(width,height,45.0f,vnear,vfar);
}
void Resize(int width, int height, double vangle)
{
Resize(width,height,vangle,0.1f,100.0f);
}
void Resize(int width, int height)
{
Resize(width,height,45.0f,0.1f,100.0f);
}
int Init()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return TRUE;
}
int Draw()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
return TRUE;
}
int Draw(DrawFunc draw)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
int ret=TRUE;
draw(&ret);
return ret;
}
void Step()
{
SwapBuffers(hDC);
}
void Kill()
{
if (fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if (hRC)
{
if (!wglMakeCurrent(NULL,NULL))
ERR("Fatal Shutdown Error!","Release of Device context and Rendering context failed.");
if (!wglDeleteContext(hRC))
ERR("Fatal Shutdown Error!","Release of Renderinc context failed.");
hRC=NULL;
}
if (hDC&&!ReleaseDC(hWnd,hDC))
{
ERR("Fatal Shutdown Error!","Release of Device context failed.");
hDC=NULL;
}
if (hWnd&&!DestroyWindow(hWnd))
{
ERR("Fatal Shutdown Error!","Release of Window failed.");
hWnd=NULL;
}
if (!UnregisterClass(classname,hInstance))
{
ERR("Fatal Shutdown Error!","Release of Windows class failed.");
hInstance=NULL;
}
}
int Create(char *title,int width,int height,int bpp, bool fscreen, int posx, int posy, char *cname)
{
unsigned int PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.top=(long)0;
WindowRect.right=(long)width;
WindowRect.bottom=(long)height;
fullscreen=fscreen;
classname=cname;
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=classname;
if (!RegisterClass(&wc))
{
ERR("Fatal Error!","Failed to register the Window class.");
return FALSE;
}
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth=width;
dmScreenSettings.dmPelsHeight=height;
dmScreenSettings.dmBitsPerPel=bpp;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSHEIGHT|DM_PELSWIDTH;
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
if (QUESTION("Fullscreen failed!","Fullscreen mode is unavailable, continue in window?")==IDYES)
{
fullscreen=false;
}
else
{
ERR("Fatal Error!","The program will now close.");
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,classname,title,WS_CLIPSIBLINGS|WS_CLIPCHILDREN|dwStyle,posx,posy,WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,NULL,NULL,hInstance,NULL)))
{
Kill();
ERR("Fatal Error!","Failed to create a window.");
return FALSE;
}
static PIXELFORMATDESCRIPTOR pfd={sizeof(PIXELFORMATDESCRIPTOR),1,PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,bpp,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE,0,0,0,0};
if (!(hDC=GetDC(hWnd)))
{
Kill();
ERR("Fatal Error!","Failed to create a device context.");
return FALSE;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
Kill();
ERR("Fatal Error!","Cannot find an acceptable pixel format.");
return FALSE;
}
if (!SetPixelFormat(hDC,PixelFormat,&pfd))
{
Kill();
ERR("Fatal Error!","Cannot see the pixel format.");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC)))
{
Kill();
ERR("Fatal Error!","Failed to create a rendering context.");
return FALSE;
}
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
Resize(width,height);
if (!Init())
{
Kill();
ERR("Fatal Error!","Faileld to initialize OpenGL.");
return FALSE;
}
return TRUE;
}
int Create(char *title,int width,int height,int bpp, bool fscreen, int posx, int posy)
{
return Create(title,width,height,bpp,fscreen,posx,posy,"OpenGL Default Window Class");
}
int Create(char *title,int width,int height,int bpp, bool fscreen, char *cname)
{
return Create(title,width,height,bpp,fscreen,0,0,cname);
}
int Create(char *title,int width,int height,int bpp, bool fscreen)
{
return Create(title,width,height,bpp,fscreen,0,0,"OpenGL Default Window Class");
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)
{
switch (umsg)
{
case WM_ACTIVATE:
if (!HIWORD(wparam))
active=TRUE;
else
active=FALSE;
return 0;
case WM_SYSCOMMAND:
switch (wparam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
KEY[wparam]=TRUE;
return 0;
case WM_KEYUP:
KEY[wparam]=FALSE;
return 0;
case WM_SIZE:
Resize(LOWORD(lparam),HIWORD(lparam));
return 0;
case WM_MOUSEMOVE:
mouse_x=GET_X_LPARAM(lparam);
mouse_y=GET_Y_LPARAM(lparam);
return 0;
case WM_MOUSEWHEEL:
deltascroll=GET_WHEEL_DELTA_WPARAM(wparam);
return 0;
}
return DefWindowProc(hwnd,umsg,wparam,lparam);
}
#endif
test.cpp:
#include "3dH.h"
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE prevInstance,LPSTR cmdline, int cmdshow)
{
MSG msg;
bool done=false;
if (!Create("TEST",640,480,32,false))
return 0;
while (!done)
{
if (MESSAGE(msg))
{
if (msg.message==WM_QUIT)
{
done=true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if ((active&&!Draw())||KEY[VK_ESCAPE])
{
done=true;
}
else
{
Step();
}
}
}
Kill();
return (msg.wParam);
}
Please help me.
NicAx64 76 Posting Pro
The only reason why wglMakeCurrent failing is as the depth that I
experience is your code is between
glBegin(...) and glEnd().
However you better call GetLastError() and get the more detailed error
information.
Many things can be happen to fail this.I have mentioned the most possible
case.
Labdabeta 182 Posting Pro in Training Featured Poster
How do you parse the DWORD into a descriptive c style string?
Labdabeta 182 Posting Pro in Training Featured Poster
I clickied and I don't understand it. I even copied and pasted the code. Still nothing!
Narue 5,707 Bad Cop Team Colleague
Wow, pretty helpless, aren't you? I'll try once more before calling it a lost cause:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
string error_text(DWORD error_code)
{
DWORD flags =
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
char *buf;
string ret;
FormatMessage(flags, 0, error_code, 0, (LPTSTR)&buf, 0, 0);
ret.assign(buf);
LocalFree(buf);
return ret;
}
int main()
{
cout << error_text(GetLastError()) << '\n';
}
Labdabeta 182 Posting Pro in Training Featured Poster
Ok, it was the weird windows typedefs that got me. Anyways I did it and it said that the command completed successfully? Nonetheless the window was clear (I could see my code right through it) and it still said release of DC and RC had failed. What now?
Narue 5,707 Bad Cop Team Colleague
Anyways I did it and it said that the command completed successfully?
Yes, because there's no error. The example was simply showing how to take an error code from GetLastError() and convert it to the system error text.
As for your continued problem, I'll leave that to people more experienced in GUI work than I.
Labdabeta 182 Posting Pro in Training Featured Poster
Not to rush the more experienced GUI programmers but... where are you guys?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.