1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*This is my first OpenGl project. Let's hope it goes well.
I'm following NeHe's tutorial at http://nehe.gamedev.net/
Started on 12/23/2011
*/
#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
//Sets up variables used in this application
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) //Prevents a divide by zero by
{
height = 1; //making height equal to 1
}
glViewport(0,0,width,height); //resets the current viewport
glMatrixMode(GL_PROJECTION); //select the project matrix
glLoadIdentity(); //Reset the project matrix
//Calculate the aspect ration 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) //All setup for OpenGL goes here
{
glShadeMode1(GL_SMOOTH); //Enables smooth shading
glClearColor(0.0f,0.0f,0.0f,0.0f); //Sets black background. Param (R,G,B,Alpha value)
glClearDepth(1.0f); //Depth buffer setup
glEnable(GL_DEPTH_TEST); //Enables depth testing
glDepthFunc(GL_EQUAL); //The type of depth test to do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Really nice perspective calculations
return TRUE; //Initialization went OK
}
int DrawGLScene(GLvoid) //Here's where all the drawing goes
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clears screen and depth buffer
glLoadIdentity(); //Reset current modelview matrix
return TRUE;
}
|