Skip to main content
GameDev.net gamedev.net
🔒 Locked

glAux Replacement Code

Started by shadowayex Oct 2, 2008 at 9:45 PM 5 replies 13.1k views
Original Post
shadowayex
shadowayex
I've seen a lot of threads about this code and everything, but I haven't found an answer for my problem. I'm new to OpenGL, and quite frankly any multi-file C++ project. I'm using Dev-C++ 4.9.9.2. Why? Because I googled "free C++ compiler" and found it, it works, and it's been able to do everything I've tried so far. Anyways, my problem: I have a project called "OpenGL" and in it I have two files, "OpenGL.cpp" and the glAux Replacement file I downloaded. When I go to compile, it gives me a multitude of errors, starting with this: 'LPTSTR' was not declared in this scope 'GLuint' was not declared in this scope 'texid' was not declared in this scope initializer expression list treated as compound expression The other errors, I believe, are created by these error. If not, then I'll ask about them as well. But for now, this code isn't working, and I don't know why. How do I fix the problem?
Caste
Caste
This shows some includes are missing, my guess is windows.h and gl/gl.h. And I guess you need to add these to the replacement code file, is there a header and a source or just a source? If there's a header (and there should be one afaik) then you need to add them there. Best thing is you tell us exactly which files you have and copy'n'paste the errors.

Carsten
MARS_999
MARS_999
You shouldn't use glAux code anymore, as most people think its crap. Whatever glaux has that you need you can code better yourself or find free libs that do the same thing.
shadowayex
shadowayex
Edit: I tried using both [codebox] and resizing
s to make it so the code was in scrollable boxes, but neither worked. Sorry for my incompetence -_-

Well, I added headers to the replacement file (the same ones I use for the main one) and still got nothing. The only reason I want the code to work is because the tutorials use it. Other than that, I know nothing of this stuff. Well, I'm giving up on that for now and I'm trying to compile just the file itself (hoping that I don't need the glAux code for it). Here's the source:

#include
#include
#include
#include

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();

//Aspect Ratio of Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid)
{
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 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.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC))
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL;
}
if (hDC && !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL;
}
if (hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL,"COuld Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL;
}
if (!UnregisterClass("OpenGL",hInstance))
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL;
}
}

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
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=fullscreenflag;

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;
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;

//try to load fullscreen
if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","ERROR",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, dwstyle);
if (!(hWnd = CreateWindowEx(dwExstyle,
"OpenGL",
"Window 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=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
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)))
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK | MB_ICONEXCLAMATION);
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))
{
KillGLWindow();
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if (!(hRC = wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if (!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"Can't Activate The GL Rendering 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;
}
}
// Anything we don't take care of
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL done = FALSE;

//Fullscreen or no?
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?","Start Fullscreen?",MB_YESNO | MB_ICONQUESTION) == IDNO)
{
fullscreen = FALSE;
}
if(!CreateGLWindow("Bwhahahahahahaha purple...",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
{
// Draw Scene. Check for Escape
if (active)
{
if (keys[VK_ESCAPE])
{
done = TRUE;
}
else
{
DrawGLScene();
SwapBuffers(hDC);
}
}
if (keys[VK_F1])
{
keys[VK_F1]=FALSE;
KillGLWindow();
fullscreen = !fullscreen;
// Recreate Window
if (!CreateGLWindow("My Window n00b!",640,480,16,fullscreen))
{
return 0;
}
}
}
}
// Shutdown
KillGLWindow();
return (msg.wParam);
}

And here are the errors:

[Linker error] undefined reference to glViewport@16'
[Linker error] undefined reference to
glMatrixMode@4'
[Linker error] undefined reference to glLoadIdentity@0'
[Linker error] undefined reference to
gluPerspective@32'
[Linker error] undefined reference to glMatrixMode@4'
[Linker error] undefined reference to
glLoadIdentity@0'
[Linker error] undefined reference to glShadeModel@4'
[Linker error] undefined reference to
glClearColor@16'
[Linker error] undefined reference to glClearDepth@8'
[Linker error] undefined reference to
glEnable@4'
[Linker error] undefined reference to glDepthFunc@4'
[Linker error] undefined reference to
glHint@8'
[Linker error] undefined reference to glClear@4'
[Linker error] undefined reference to
glLoadIdentity@0'
[Linker error] undefined reference to wglMakeCurrent@8'
[Linker error] undefined reference to
wglDeleteContext@4'
[Linker error] undefined reference to ChoosePixelFormat@8'
[Linker error] undefined reference to
SetPixelFormat@12'
[Linker error] undefined reference to wglCreateContext@4'
[Linker error] undefined reference to
wglMakeCurrent@8'
[Linker error] undefined reference to SwapBuffers@4'
ld returned 1 exit status

And in case anyone wants to take a swing at it, here's the source for the glAux replacement and it's errors:

Source
/************************************************************************
REPLACEMENT FOR GLAUX
************************************************************************
This is not a full blown bitmap loader. It is a quick and easy
way to replace the glAux dependant code in my older tutorials
with code that does not depend on the glAux library!

This code only loads Truecolor Bitmap Images. It will not load
8-bit bitmaps. If you encounter a bitmap that will not load
use a program such as Irfanview to convert the bitmap to 24 bits.
************************************************************************/

#include
#include
#include
#include

bool NeHeLoadBitmap(LPTSTR szFileName, GLuint &texid) // Creates Texture From A Bitmap File
{
HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

glGenTextures(1, &texid); // Create The Texture
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );

if (!hBMP) // Does The Bitmap Exist?
return FALSE; // If Not Return False

GetObject(hBMP, sizeof(BMP), &BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// &BMP: Buffer For Object Information

glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // Pixel Storage Mode (Word Alignment / 4 Bytes)

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texid); // Bind To The Texture ID
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Min Filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Mag Filter
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

DeleteObject(hBMP); // Delete The Object

return TRUE; // Loading Was Successful
}

BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here
{
g_window = window;
g_keys = keys;

// Start Of User Initialization
if (!NeHeLoadBitmap("Data/NeHe.bmp", texture[0])) // Load The Bitmap
return FALSE; // Return False If Loading Failed

Errors:
47 E:\OpenGL3\glAux Replacement.cpp
GL_Window' was not declared in this scope
47 E:\OpenGL3\glAux Replacement.cpp window' was not declared in this scope
47 E:\OpenGL3\glAux Replacement.cpp
Keys' was not declared in this scope
47 E:\OpenGL3\glAux Replacement.cpp keys' was not declared in this scope
48 E:\OpenGL3\glAux Replacement.cpp initializer expression list treated as compound expression
48 E:\OpenGL3\glAux Replacement.cpp expected
,' or `;' before '{' token

And FYI, line 47 is: BOOL Initialize (GL_Window* window, Keys* keys)
xZekex
xZekex
First of all dump Dev-C++ and get Visual Studio 2008 Express Edition C++. Dev-C++ is 5 years old and not being updated.

Don't use the glAux header or the glAux replacement. Google for devIL. It is way better than that and supports alot more image formats.

Please for the love of god edit you code and wrap it in the source code tags.

I won't bother reading it until then >.< and your forgetting to link to the opengl libraries.
shadowayex
shadowayex
xZekex
I tried Visual Studio and HATE it. I can't use it near as effectively as I can Dev-Cpp. Secondly, that code up there is the EXACT code from Nehe Productions' first tutorial. I'm not experienced in OpenGL and that is why I'm using these tutorials. If you have a problem with it, it's there bad I guess. I'm probably going to give up on OpenGL soon since no one seems to have a decency to help a n00b out instead of saying "rewrite it then I'll help," which doesn't help me anyhow considering I didn't originally write the code. I just retyped it how they have it and put it in the compiler and got the above errors.

I can't seem to get the code to compile in Visual Studio either. I even downloaded the code from the site itself and it have some random error.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.