Jump to content
  • Advertisement
Sign in to follow this  
basudev1311

unresolved external symbol _auxDIBImageLoadA@4

This topic is 4303 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

having this problem for a while now. here's the code.
[
#include <windows.h>		// Header File For Windows
#include <gl\glut.h>			// Header File For The GLu32 Library
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <fstream.h>
#include <stdlib.h>
#include <math.h>

HDC			hDC=NULL;		// Private GDI Device Context
HGLRC		hRC=NULL;		// Permanent Rendering Context
HWND		hWnd=NULL;		// Holds Our Window Handle
HINSTANCE	hInstance;		// Holds The Instance Of The Application

GLuint g_textureID = -1;

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

#define ID_TIMER 1

bool Attenuate = FALSE;

float xRot = -30, yRot=0, increment=1;

float yAngLig = 0, radius1 = 10.0, radius2 = 10.0, Ang=0;

int Widths[] = {	640, 800, 1024, 1280, 1600, 1680	};
int Heights[] = {	480, 600, 768, 800, 1200, 1050	};

float light0_position[] = { .0, 2.0, 0.0, 1.0 };
float light0_color[] = { 1.0, 0.0, 0.0, 1.0 };

float light1_position[] = { 0.0, 2.0, 0.0, 1.0 };
float light1_color[] = { 0.0, 1.0, 0, 1.0 };

float light2_position[] = { 0.0, 2.0, 0.0, 1.0 };
float light2_color[] = { 0.0, 0.0, 1.0, 1.0 };

int choice;

struct Vertex
{
    // GL_T2F_V3F
    float tu, tv;
    float x, y, z;
};

Vertex g_quadVertices[] =
{
    { 0.0f,0.0f, -1.0f,-1.0f, 0.0f },
    { 1.0f,0.0f,  1.0f,-1.0f, 0.0f },
    { 1.0f,1.0f,  1.0f, 1.0f, 0.0f },
    { 0.0f,1.0f, -1.0f, 1.0f, 0.0f }
};

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

int get_Res_Choice()
{
//	ifstream infile("Res_Choice.txt");
//	infile >> choice;
	choice=3;
	return choice;
}

int Set_Width()
{
	get_Res_Choice(); 
	int SCR_WIDTH = Widths[get_Res_Choice()];
	return SCR_WIDTH;
}

int Set_Height()
{
	get_Res_Choice();
	int SCR_HEIGHT = Heights[get_Res_Choice()];
	return SCR_HEIGHT;
}

void loadTexture(void)	
{
	AUX_RGBImageRec *pTextureImage = auxDIBImageLoad( "woodfloor.bmp" );

    if( pTextureImage != NULL )
	{
        glGenTextures( 1, &g_textureID );

		glBindTexture( GL_TEXTURE_2D, g_textureID );

		glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );

		glTexImage2D( GL_TEXTURE_2D, 0, 3, pTextureImage->sizeX, pTextureImage->sizeY, 0,
				GL_RGB, GL_UNSIGNED_BYTE, pTextureImage->data );
	}

	if( pTextureImage )
	{
		if( pTextureImage->data )
			free( pTextureImage->data );

		free( pTextureImage );
	}
}

void Update_Light_Positions()
{
	light0_position[0] = radius1 * cos(yAngLig);
	light0_position[2] = radius2 * sin(yAngLig);

	light1_position[0] = radius1 * cos(yAngLig/2);
	light1_position[2] = radius2 * sin(yAngLig/2);

	light2_position[0] = radius1 * cos(yAngLig/4);
	light2_position[2] = radius2 * sin(yAngLig/4);

	yAngLig+=0.02;
}

void BP_Draw_Light0()
{	
	glEnable(GL_LIGHT0);
	
	glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);

	if(Attenuate==TRUE)
	{
 		glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
		glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.1);
		glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.1);
	}
		
	glDisable(GL_LIGHTING);
	glColor3fv(light0_color );
	glTranslatef(light0_position[0], light0_position[1], light0_position[2]);
	glutSolidSphere(0.2, 8, 8);
	glTranslatef(-light0_position[0], -light0_position[1], -light0_position[2]);
	glEnable(GL_LIGHTING);
}

void BP_Draw_Light1()
{
	glEnable(GL_LIGHT1);
	
	glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color);
 	
	if(Attenuate==TRUE)
	{
		glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
		glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.1);
		glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.1);
	}
 	
	glDisable(GL_LIGHTING);
	glColor3fv(light1_color);
	glTranslatef(light1_position[0], light1_position[1], light1_position[2]);
	glutSolidSphere(0.2, 8, 8);
	glTranslatef(-light1_position[0], -light1_position[1], -light1_position[2]);
	glEnable(GL_LIGHTING);
}

void BP_Draw_Light2()
{
	glEnable(GL_LIGHT2);
	
	glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
	glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_color);
 	
	if(Attenuate==TRUE)
	{
		glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 0.1);
		glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 0.1);
		glLightf(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, 0.1);
	}
 		
	glDisable(GL_LIGHTING);
	glColor3fv(light2_color);
	glTranslatef(light2_position[0], light2_position[1], light2_position[2]);
	glutSolidSphere(0.2, 8, 8);
	glTranslatef(-light2_position[0], -light2_position[1], -light2_position[2]);
	glEnable(GL_LIGHTING);
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	glViewport(0,0,width,height);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

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

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int InitGL(GLvoid)
{
//	loadTexture();

	glShadeModel(GL_SMOOTH);
	
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	
	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();

	gluLookAt(0, 20, 50, 0, 0, 0, 0, 1, 0);

	glRotatef(yRot, 1, 0, 0);
	glRotatef(xRot, 0, 1, 0);

	BP_Draw_Light0();
	BP_Draw_Light1();
	BP_Draw_Light2();

    glScalef(10, 10, 10);
	glBindTexture( GL_TEXTURE_2D, g_textureID );
    glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices );
    glDrawArrays( GL_QUADS, 0, 4 );

	return TRUE;
}

GLvoid KillGLWindow(GLvoid)								// Properly Kill The Window
{
	if (fullscreen)										// Are We In Fullscreen Mode?
	{
		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
		ShowCursor(TRUE);								// Show Mouse Pointer
	}
}

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExstyle;				// Window Extended style
	DWORD		dwstyle;				// Window style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name

	RegisterClass(&wc);

	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
	}

	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExstyle=WS_EX_APPWINDOW;								// Window Extended style
		dwstyle=WS_POPUP;										// Windows style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExstyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended style
		dwstyle=WS_OVERLAPPEDWINDOW;							// Windows style
	}

	AdjustWindowRectEx(&WindowRect, dwstyle, FALSE, dwExstyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExstyle,							// Extended style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwstyle |							// Defined Window style
								WS_CLIPSIBLINGS |					// Required Window style
								WS_CLIPCHILDREN,					// Required Window style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// 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
	};
	
	hDC=GetDC(hWnd);
	PixelFormat=ChoosePixelFormat(hDC,&pfd);
	SetPixelFormat(hDC,PixelFormat,&pfd);
	
	hRC=wglCreateContext(hDC);
	wglMakeCurrent(hDC,hRC);

	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	
	InitGL();
	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen

	return TRUE;									// Success
}

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
		{
			SetTimer (hWnd, ID_TIMER, 10, NULL) ;
			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_TIMER:
		{
			case ID_TIMER:
				{
				if(GetAsyncKeyState(VK_UP))
					yRot-=increment;

				if(GetAsyncKeyState(VK_DOWN))
					yRot+=increment;

				if(GetAsyncKeyState(VK_LEFT))
					xRot-=increment;

				if(GetAsyncKeyState(VK_RIGHT))
					xRot+=increment;

				Update_Light_Positions();
				}

				break;
		}

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

int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	done=FALSE;								// Bool Variable To Exit Loop

	// Create Our OpenGL Window
	if (!CreateGLWindow("NeHe's OpenGL Framework", Set_Width(), Set_Height(), 32, fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if (active)								// Program Active?
			{
				if (keys[VK_ESCAPE])				// Was ESC Pressed?
				{
					done=TRUE;						// ESC Signalled A Quit
				}
				else								// Not Time To Quit, Update Screen
				{
					DrawGLScene();					// Draw The Scene
					SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
				}
			}

		}
	}

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}
]
[Edited by - basudev1311 on August 11, 2006 8:17:33 AM]

Share this post


Link to post
Share on other sites
Advertisement
sorry about the long code.
don't know how to do that code in a scroll box thing.
/*DONE*/

[Edited by - basudev1311 on August 11, 2006 8:59:40 AM]

Share this post


Link to post
Share on other sites
Posting of source code is covered in the FAQ.

As you your problem you either want to link glaux.lib to your project or, better, replace the bitmap loading code with the glaux replacement code from the NeHe site.

Σnigma

Share this post


Link to post
Share on other sites
Thanx a lot.
I finally managed to get something textured. Really Happy.

But it runs quite slow. I think i'm really missing something.



#include <windows.h> // Header File For Windows
#include <gl\glut.h> // Header File For The GLu32 Library
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <fstream.h>
#include <stdlib.h>
#include <math.h>

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

GLuint texture[1];

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

#define ID_TIMER 1

bool Attenuate = FALSE;

float xRot = -30, yRot=0, increment=1;

float yAngLig = 0, radius1 = 10.0, radius2 = 10.0, Ang=0;

int Widths[] = { 640, 800, 1024, 1280, 1600, 1680 };
int Heights[] = { 480, 600, 768, 800, 1200, 1050 };

float light0_position[] = { .0, 2.0, 0.0, 1.0 };
float light0_color[] = { 1.0, 0.0, 0.0, 1.0 };

float light1_position[] = { 0.0, 2.0, 0.0, 1.0 };
float light1_color[] = { 0.0, 1.0, 0, 1.0 };

float light2_position[] = { 0.0, 2.0, 0.0, 1.0 };
float light2_color[] = { 0.0, 0.0, 1.0, 1.0 };

int choice;

struct Vertex
{
// GL_T2F_V3F
float tu, tv;
float x, y, z;
};

Vertex g_quadVertices[] =
{
{ 0.0f,0.0f, -1.0f,-1.0f, 0.0f },
{ 1.0f,0.0f, 1.0f,-1.0f, 0.0f },
{ 1.0f,1.0f, 1.0f, 1.0f, 0.0f },
{ 0.0f,1.0f, -1.0f, 1.0f, 0.0f }
};

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

int get_Res_Choice()
{
// ifstream infile("Res_Choice.txt");
// infile >> choice;
choice=3;
return choice;
}

int Set_Width()
{
get_Res_Choice();
int SCR_WIDTH = Widths[get_Res_Choice()];
return SCR_WIDTH;
}

int Set_Height()
{
get_Res_Choice();
int SCR_HEIGHT = Heights[get_Res_Choice()];
return SCR_HEIGHT;
}

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_NEAREST); // Linear Min Filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 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
}

void Update_Light_Positions()
{
light0_position[0] = radius1 * cos(yAngLig);
light0_position[2] = radius2 * sin(yAngLig);

light1_position[0] = radius1 * cos(yAngLig/2);
light1_position[2] = radius2 * sin(yAngLig/2);

light2_position[0] = radius1 * cos(yAngLig/4);
light2_position[2] = radius2 * sin(yAngLig/4);

yAngLig+=0.02;
}

void BP_Draw_Light0()
{
glEnable(GL_LIGHT0);

glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);

if(Attenuate==TRUE)
{
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.1);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.1);
}

glDisable(GL_LIGHTING);
glColor3fv(light0_color );
glTranslatef(light0_position[0], light0_position[1], light0_position[2]);
glutSolidSphere(0.2, 8, 8);
glTranslatef(-light0_position[0], -light0_position[1], -light0_position[2]);
glEnable(GL_LIGHTING);
}

void BP_Draw_Light1()
{
glEnable(GL_LIGHT1);

glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color);

if(Attenuate==TRUE)
{
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.1);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.1);
}

glDisable(GL_LIGHTING);
glColor3fv(light1_color);
glTranslatef(light1_position[0], light1_position[1], light1_position[2]);
glutSolidSphere(0.2, 8, 8);
glTranslatef(-light1_position[0], -light1_position[1], -light1_position[2]);
glEnable(GL_LIGHTING);
}

void BP_Draw_Light2()
{
glEnable(GL_LIGHT2);

glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_color);

if(Attenuate==TRUE)
{
glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 0.1);
glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 0.1);
glLightf(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, 0.1);
}

glDisable(GL_LIGHTING);
glColor3fv(light2_color);
glTranslatef(light2_position[0], light2_position[1], light2_position[2]);
glutSolidSphere(0.2, 8, 8);
glTranslatef(-light2_position[0], -light2_position[1], -light2_position[2]);
glEnable(GL_LIGHTING);
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

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

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid)
{
NeHeLoadBitmap("woodfloor.bmp", texture[0]);

glShadeModel(GL_SMOOTH);

glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
// glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);

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

gluLookAt(0, 20, 50, 0, 0, 0, 0, 1, 0);

glRotatef(yRot, 1, 0, 0);
glRotatef(xRot, 0, 1, 0);

glScalef(10, 10, 10);
glBindTexture( GL_TEXTURE_2D, texture[0] );
glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices );
glDrawArrays( GL_QUADS, 0, 4 );

return TRUE;
}

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}
}

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height

fullscreen=fullscreenflag; // Set The Global Fullscreen Flag

hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name

RegisterClass(&wc);

if (fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
}

if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size

// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // 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
};

hDC=GetDC(hWnd);
PixelFormat=ChoosePixelFormat(hDC,&pfd);
SetPixelFormat(hDC,PixelFormat,&pfd);

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

ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window

InitGL();
ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen

return TRUE; // Success
}

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
{
SetTimer (hWnd, ID_TIMER, 10, NULL) ;
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_TIMER:
{
case ID_TIMER:
{
if(GetAsyncKeyState(VK_UP))
yRot-=increment;

if(GetAsyncKeyState(VK_DOWN))
yRot+=increment;

if(GetAsyncKeyState(VK_LEFT))
xRot-=increment;

if(GetAsyncKeyState(VK_RIGHT))
xRot+=increment;

Update_Light_Positions();
}

break;
}

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

int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop

// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's OpenGL Framework", Set_Width(), Set_Height(), 32, fullscreen))
{
return 0; // Quit If Window Was Not Created
}

while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if (active) // Program Active?
{
if (keys[VK_ESCAPE]) // Was ESC Pressed?
{
done=TRUE; // ESC Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
DrawGLScene(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}

}
}

// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!