oce

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

100 Neutral

About oce

  • Rank
    Newbie
  1. Hello, I am having trouble adding a new shape to morph to along with the original shapes in lesson 25. If you could give an example of how to add a cube or a pyramid it would clarify as to how to go about adding new shapes. Here is my code (with new portions in red): [size="2"][color="#0000ff"][size="2"][color="#0000ff"]#include[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]<windows.h>[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Header File For Windows[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]#include[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]<math.h>[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Math Library Header File[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]#include[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]<stdio.h>[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Header File For Standard Input/Output[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]#include[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]<gl\gl.h>[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Header File For The OpenGL32 Library[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]#include[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]<gl\glu.h>[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Header File For The GLu32 Library[/color][/size][/color][/size] [size="2"]HDC hDC=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Device Context Handle[/color][/size][/color][/size] [size="2"]HGLRC hRC=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Rendering Context Handle[/color][/size][/color][/size] [size="2"]HWND hWnd=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Handle[/color][/size][/color][/size] [size="2"]HINSTANCE hInstance; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Instance Handle[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size] [size="2"]keys[256]; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Key Array[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size] [size="2"]active=TRUE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Program's Active[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size] [size="2"]fullscreen=TRUE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Default Fullscreen To True[/color][/size][/color][/size] [size="2"]GLfloat xrot,yrot,zrot, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// X, Y & Z Rotation[/color][/size][/color][/size] [size="2"]xspeed,yspeed,zspeed, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// X, Y & Z Spin Speed[/color][/size][/color][/size] [size="2"]cx,cy,cz=-15; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// X, Y & Z Position[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size] [size="2"]key=1; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Used To Make Sure Same Morph Key Is Not Pressed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size] [size="2"]step=0,steps=10; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Step Counter And Maximum Number Of Steps[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size] [size="2"]morph=FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Default morph To False (Not Morphing)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]typedef[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]struct[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Structure For 3D Points[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]float[/color][/size][/color][/size][size="2"] x, y, z; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// X, Y & Z Points[/color][/size][/color][/size] [size="2"]} VERTEX; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Called VERTEX[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]typedef[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]struct[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Structure For An Object[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] verts; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Number Of Vertices For The Object[/color][/size][/color][/size] [size="2"]VERTEX *points; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// One Vertice (Vertex x,y & z)[/color][/size][/color][/size] [size="2"]} OBJECT; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Called OBJECT[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size] [size="2"]maxver; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Will Eventually Hold The Maximum Number Of Vertices[/color][/size][/color][/size] [size="2"]OBJECT morph1,morph2,morph3,morph4,[color=#FF0000]morph5,[/color] [color="#ff0000"]//new morph object[/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Our 4 Morphable Objects (morph1,2,3 & 4)[/color][/size][/color][/size] [size="2"]helper,*sour,*dest; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Helper Object, Source Object, Destination Object[/color][/size][/color][/size] [size="2"]LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Declaration[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size] [size="2"]objallocate(OBJECT *k,[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] n) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Allocate Memory For Each Object[/color][/size][/color][/size] [size="2"]{ [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// And Defines points[/color][/size][/color][/size] [size="2"]k->points=(VERTEX*)malloc([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]sizeof[/color][/size][/color][/size][size="2"](VERTEX)*n); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Sets points Equal To VERTEX * Number Of Vertices[/color][/size][/color][/size] [size="2"]} [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// (3 Points For Each Vertice)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size] [size="2"]objfree(OBJECT *k) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Frees The Object (Releasing The Memory)[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]free(k->points); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Frees Points[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size] [size="2"]readstr(FILE *f,[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]char[/color][/size][/color][/size][size="2"] *string) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Reads A String From File (f)[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]do[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Do This[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]fgets(string, 255, f); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Gets A String Of 255 Chars Max From f (File)[/color][/size][/color][/size] [size="2"]} [/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]while[/color][/size][/color][/size][size="2"] ((string[0] == [/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'/'[/color][/size][/color][/size][size="2"]) || (string[0] == [/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'\n'[/color][/size][/color][/size][size="2"]));[/size][size="2"][color="#008000"][size="2"][color="#008000"]// Until End Of Line Is Reached[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"]; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size] [size="2"]objload([/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]char[/color][/size][/color][/size][size="2"] *name,OBJECT *k) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Loads Object From File (name)[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] ver; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Will Hold Vertice Count[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]float[/color][/size][/color][/size][size="2"] rx,ry,rz; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Hold Vertex X, Y & Z Position[/color][/size][/color][/size] [size="2"]FILE *filein; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Filename To Open[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]char[/color][/size][/color][/size][size="2"] oneline[255]; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Holds One Line Of Text (255 Chars Max)[/color][/size][/color][/size] [size="2"]filein = fopen(name, [/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"rt"[/color][/size][/color][/size][size="2"]); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Opens The File For Reading Text In Translated Mode[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// CTRL Z Symbolizes End Of File In Translated Mode[/color][/size][/color][/size] [size="2"]readstr(filein,oneline); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jumps To Code That Reads One Line Of Text From The File[/color][/size][/color][/size] [size="2"]sscanf(oneline, [/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Vertices: %d\n"[/color][/size][/color][/size][size="2"], &ver); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Scans Text For "Vertices: ". Number After Is Stored In ver[/color][/size][/color][/size] [size="2"]k->verts=ver; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Objects verts Variable To Equal The Value Of ver[/color][/size][/color][/size] [size="2"]objallocate(k,ver); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jumps To Code That Allocates Ram To Hold The Object[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]for[/color][/size][/color][/size][size="2"] ([/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] i=0;i<ver;i++) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Loops Through The Vertices[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]readstr(filein,oneline); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reads In The Next Line Of Text[/color][/size][/color][/size] [size="2"]sscanf(oneline, [/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"%f %f %f"[/color][/size][/color][/size][size="2"], &rx, &ry, &rz); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Searches For 3 Floating Point Numbers, Store In rx,ry & rz[/color][/size][/color][/size] [size="2"]k->points[i].x = rx; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Objects (k) points.x Value To rx[/color][/size][/color][/size] [size="2"]k->points[i].y = ry; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Objects (k) points.y Value To ry[/color][/size][/color][/size] [size="2"]k->points[i].z = rz; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Objects (k) points.z Value To rz[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]fclose(filein); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Close The File[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](ver>maxver) maxver=ver; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// If ver Is Greater Than maxver Set maxver Equal To ver[/color][/size][/color][/size] [size="2"]} [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Keeps Track Of Highest Number Of Vertices Used In Any Of The[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Objects[/color][/size][/color][/size] [size="2"]VERTEX calculate([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] i) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Calculates Movement Of Points During Morphing[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]VERTEX a; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Temporary Vertex Called a[/color][/size][/color][/size] [size="2"]a.x=(sour->points[i].x-dest->points[i].x)/steps; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// a.x Value Equals Source x - Destination x Divided By Steps[/color][/size][/color][/size] [size="2"]a.y=(sour->points[i].y-dest->points[i].y)/steps; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// a.y Value Equals Source y - Destination y Divided By Steps[/color][/size][/color][/size] [size="2"]a.z=(sour->points[i].z-dest->points[i].z)/steps; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// a.z Value Equals Source z - Destination z Divided By Steps[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] a; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return The Results[/color][/size][/color][/size] [size="2"]} [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// This Makes Points Move At A Speed So They All Get To Their[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Destination At The Same Time[/color][/size][/color][/size] [size="2"]GLvoid ReSizeGLScene(GLsizei width, GLsizei height) [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Resize And Initialize The GL Window[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (height==0) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Prevent A Divide By Zero By[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]height=1; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Making Height Equal One[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]glViewport(0,0,width,height); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Current Viewport[/color][/size][/color][/size] [size="2"]glMatrixMode(GL_PROJECTION); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Select The Projection Matrix[/color][/size][/color][/size] [size="2"]glLoadIdentity(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Projection Matrix[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Calculate The Aspect Ratio Of The Window[/color][/size][/color][/size] [size="2"]gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);[/size] [size="2"]glMatrixMode(GL_MODELVIEW); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Select The Modelview Matrix[/color][/size][/color][/size] [size="2"]glLoadIdentity(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Modelview Matrix[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size] [size="2"]InitGL(GLvoid) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// All Setup For OpenGL Goes Here[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]glBlendFunc(GL_SRC_ALPHA,GL_ONE); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set The Blending Function For Translucency[/color][/size][/color][/size] [size="2"]glClearColor(0.0f, 0.0f, 0.0f, 0.0f); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// This Will Clear The Background Color To Black[/color][/size][/color][/size] [size="2"]glClearDepth(1.0); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Enables Clearing Of The Depth Buffer[/color][/size][/color][/size] [size="2"]glDepthFunc(GL_LESS); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// The Type Of Depth Test To Do[/color][/size][/color][/size] [size="2"]glEnable(GL_DEPTH_TEST); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Enables Depth Testing[/color][/size][/color][/size] [size="2"]glShadeModel(GL_SMOOTH); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Enables Smooth Color Shading[/color][/size][/color][/size] [size="2"]glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Really Nice Perspective Calculations[/color][/size][/color][/size] [size="2"]maxver=0; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Max Vertices To 0 By Default[/color][/size][/color][/size] [size="2"]objload([/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"data/sphere.txt"[/color][/size][/color][/size][size="2"],&morph1); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Load The First Object Into morph1 From File sphere.txt[/color][/size][/color][/size] [size="2"]objload([/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"data/torus.txt"[/color][/size][/color][/size][size="2"],&morph2); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Load The Second Object Into morph2 From File torus.txt[/color][/size][/color][/size] [size="2"]objload([/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"data/tube.txt"[/color][/size][/color][/size][size="2"],&morph3); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Load The Third Object Into morph3 From File tube.txt[/color][/size][/color][/size] [color=#FF0000][size="2"]objload([/size][/color] [color=#FF0000][size="2"][size="2"]"data/tube2.txt"[/size][/size][size="2"],&morph5); //new call for loading of vertices from file (note: vertices were copied from 1 of the original files to see if object would appear but failed[/size][/color] [size="2"]objallocate(&morph4,24); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Manually Reserver Ram For A 4th 468 Vertice Object (morph4)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]for[/color][/size][/color][/size][size="2"]([/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] i=0;i<24;i++) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Loop Through All 468 Vertices[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]morph4.points[i].x=(([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]float[/color][/size][/color][/size][size="2"])(rand()%14000)/1000)-7; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// morph4 x Point Becomes A Random Float Value From -7 to 7[/color][/size][/color][/size] [size="2"]morph4.points[i].y=(([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]float[/color][/size][/color][/size][size="2"])(rand()%14000)/1000)-7; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// morph4 y Point Becomes A Random Float Value From -7 to 7[/color][/size][/color][/size] [size="2"]morph4.points[i].z=(([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]float[/color][/size][/color][/size][size="2"])(rand()%14000)/1000)-7; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// morph4 z Point Becomes A Random Float Value From -7 to 7[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]objload([/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"data/sphere.txt"[/color][/size][/color][/size][size="2"],&helper); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Load sphere.txt Object Into Helper (Used As Starting Point)[/color][/size][/color][/size] [size="2"]sour=dest=&morph1; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Source & Destination Are Set To Equal First Object (morph1)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] TRUE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Initialization Went OK[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]void[/color][/size][/color][/size] [size="2"]DrawGLScene(GLvoid) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Here's Where We Do All The Drawing[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Clear The Screen And The Depth Buffer[/color][/size][/color][/size] [size="2"]glLoadIdentity(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The View[/color][/size][/color][/size] [size="2"]glTranslatef(cx,cy,cz); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Translate The The Current Position To Start Drawing[/color][/size][/color][/size] [size="2"]glRotatef(xrot,1,0,0); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Rotate On The X Axis By xrot[/color][/size][/color][/size] [size="2"]glRotatef(yrot,0,1,0); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Rotate On The Y Axis By yrot[/color][/size][/color][/size] [size="2"]glRotatef(zrot,0,0,1); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Rotate On The Z Axis By zrot[/color][/size][/color][/size] [size="2"]xrot+=xspeed; yrot+=yspeed; zrot+=zspeed; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Increase xrot,yrot & zrot by xspeed, yspeed & zspeed[/color][/size][/color][/size] [size="2"]GLfloat tx,ty,tz; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Temp X, Y & Z Variables[/color][/size][/color][/size] [size="2"]VERTEX q; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Holds Returned Calculated Values For One Vertex[/color][/size][/color][/size] [size="2"]glBegin(GL_POINTS); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Begin Drawing Points[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]for[/color][/size][/color][/size][size="2"]([/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] i=0;i<morph1.verts;i++) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Loop Through All The Verts Of morph1 (All Objects Have[/color][/size][/color][/size] [size="2"]{ [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// The Same Amount Of Verts For Simplicity, Could Use maxver Also)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](morph) q=calculate(i); [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size][size="2"] q.x=q.y=q.z=0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// If morph Is True Calculate Movement Otherwise Movement=0[/color][/size][/color][/size] [size="2"]helper.points[i].x-=q.x; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Subtract q.x Units From helper.points[i].x (Move On X Axis)[/color][/size][/color][/size] [size="2"]helper.points[i].y-=q.y; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Subtract q.y Units From helper.points[i].y (Move On Y Axis)[/color][/size][/color][/size] [size="2"]helper.points[i].z-=q.z; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Subtract q.z Units From helper.points[i].z (Move On Z Axis)[/color][/size][/color][/size] [size="2"]tx=helper.points[i].x; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Make Temp X Variable Equal To Helper's X Variable[/color][/size][/color][/size] [size="2"]ty=helper.points[i].y; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Make Temp Y Variable Equal To Helper's Y Variable[/color][/size][/color][/size] [size="2"]tz=helper.points[i].z; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Make Temp Z Variable Equal To Helper's Z Variable[/color][/size][/color][/size] [size="2"]glColor3f(0,1,1); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set Color To A Bright Shade Of Off Blue[/color][/size][/color][/size] [size="2"]glVertex3f(tx,ty,tz); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Draw A Point At The Current Temp Values (Vertex)[/color][/size][/color][/size] [size="2"]glColor3f(0,0.5f,1); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Darken Color A Bit[/color][/size][/color][/size] [size="2"]tx-=2*q.x; ty-=2*q.y; ty-=2*q.y; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Calculate Two Positions Ahead[/color][/size][/color][/size] [size="2"]glVertex3f(tx,ty,tz); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Draw A Second Point At The Newly Calculate Position[/color][/size][/color][/size] [size="2"]glColor3f(0,0,1); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set Color To A Very Dark Blue[/color][/size][/color][/size] [size="2"]tx-=2*q.x; ty-=2*q.y; ty-=2*q.y; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Calculate Two More Positions Ahead[/color][/size][/color][/size] [size="2"]glVertex3f(tx,ty,tz); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Draw A Third Point At The Second New Position[/color][/size][/color][/size] [size="2"]} [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// This Creates A Ghostly Tail As Points Move[/color][/size][/color][/size] [size="2"]glEnd(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Done Drawing Points[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If We're Morphing And We Haven't Gone Through All 200 Steps Increase Our Step Counter[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Otherwise Set Morphing To False, Make Source=Destination And Set The Step Counter Back To Zero.[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](morph && step<=steps)step++; [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size][size="2"] { morph=FALSE; sour=dest; step=0;}[/size] [size="2"]}[/size] [size="2"]GLvoid KillGLWindow(GLvoid) [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Properly Kill The Window[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]objfree(&morph1); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jump To Code To Release morph1 Allocated Ram[/color][/size][/color][/size] [size="2"]objfree(&morph2); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jump To Code To Release morph2 Allocated Ram[/color][/size][/color][/size] [size="2"]objfree(&morph3); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jump To Code To Release morph3 Allocated Ram[/color][/size][/color][/size] [size="2"]objfree(&morph4); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jump To Code To Release morph4 Allocated Ram[/color][/size][/color][/size] [color=#FF0000][size="2"]objfree(&morph5);[/size][/color] [size="2"]objfree(&helper); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Jump To Code To Release helper Allocated Ram[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (fullscreen) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We In Fullscreen Mode?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]ChangeDisplaySettings(NULL,0); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If So Switch Back To The Desktop[/color][/size][/color][/size] [size="2"]ShowCursor(TRUE); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Show Mouse Pointer[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (hRC) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Do We Have A Rendering Context?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!wglMakeCurrent(NULL,NULL)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Release The DC And RC Contexts?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Release Of DC And RC Failed."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"SHUTDOWN ERROR"[/color][/size][/color][/size][size="2"],MB_OK | MB_ICONINFORMATION);[/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!wglDeleteContext(hRC)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Delete The RC?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Release Rendering Context Failed."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"SHUTDOWN ERROR"[/color][/size][/color][/size][size="2"],MB_OK | MB_ICONINFORMATION);[/size] [size="2"]}[/size] [size="2"]hRC=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set RC To NULL[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (hDC && !ReleaseDC(hWnd,hDC)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Release The DC[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Release Device Context Failed."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"SHUTDOWN ERROR"[/color][/size][/color][/size][size="2"],MB_OK | MB_ICONINFORMATION);[/size] [size="2"]hDC=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set DC To NULL[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (hWnd && !DestroyWindow(hWnd)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Destroy The Window?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Could Not Release hWnd."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"SHUTDOWN ERROR"[/color][/size][/color][/size][size="2"],MB_OK | MB_ICONINFORMATION);[/size] [size="2"]hWnd=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set hWnd To NULL[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!UnregisterClass([/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"OpenGL"[/color][/size][/color][/size][size="2"],hInstance)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Unregister Class[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Could Not Unregister Class."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"SHUTDOWN ERROR"[/color][/size][/color][/size][size="2"],MB_OK | MB_ICONINFORMATION);[/size] [size="2"]hInstance=NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set hInstance To NULL[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"][color="#008000"][size="2"][color="#008000"]/* This Code Creates Our OpenGL Window. Parameters Are: *[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]* title - Title To Appear At The Top Of The Window *[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]* width - Width Of The GL Window Or Fullscreen Mode *[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]* height - Height Of The GL Window Or Fullscreen Mode *[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]* bits - Number Of Bits To Use For Color (8/16/24/32) *[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */[/color][/size][/color][/size] [size="2"]BOOL CreateGLWindow([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]char[/color][/size][/color][/size][size="2"]* title, [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] width, [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] height, [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] bits, [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size][size="2"] fullscreenflag)[/size] [size="2"]{[/size] [size="2"]GLuint PixelFormat; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Holds The Results After Searching For A Match[/color][/size][/color][/size] [size="2"]WNDCLASS wc; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windows Class Structure[/color][/size][/color][/size] [size="2"]DWORD dwExStyle; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Extended Style[/color][/size][/color][/size] [size="2"]DWORD dwStyle; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Style[/color][/size][/color][/size] [size="2"]RECT WindowRect; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Grabs Rectangle Upper Left / Lower Right Values[/color][/size][/color][/size] [size="2"]WindowRect.left=([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]long[/color][/size][/color][/size][size="2"])0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Set Left Value To 0[/color][/size][/color][/size] [size="2"]WindowRect.right=([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]long[/color][/size][/color][/size][size="2"])width; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Set Right Value To Requested Width[/color][/size][/color][/size] [size="2"]WindowRect.top=([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]long[/color][/size][/color][/size][size="2"])0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Set Top Value To 0[/color][/size][/color][/size] [size="2"]WindowRect.bottom=([/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]long[/color][/size][/color][/size][size="2"])height; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Set Bottom Value To Requested Height[/color][/size][/color][/size] [size="2"]fullscreen=fullscreenflag; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set The Global Fullscreen Flag[/color][/size][/color][/size] [size="2"]hInstance = GetModuleHandle(NULL); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Grab An Instance For Our Window[/color][/size][/color][/size] [size="2"]wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Redraw On Size, And Own DC For Window.[/color][/size][/color][/size] [size="2"]wc.lpfnWndProc = (WNDPROC) WndProc; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// WndProc Handles Messages[/color][/size][/color][/size] [size="2"]wc.cbClsExtra = 0; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Extra Window Data[/color][/size][/color][/size] [size="2"]wc.cbWndExtra = 0; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Extra Window Data[/color][/size][/color][/size] [size="2"]wc.hInstance = hInstance; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set The Instance[/color][/size][/color][/size] [size="2"]wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Load The Default Icon[/color][/size][/color][/size] [size="2"]wc.hCursor = LoadCursor(NULL, IDC_ARROW); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Load The Arrow Pointer[/color][/size][/color][/size] [size="2"]wc.hbrBackground = NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Background Required For GL[/color][/size][/color][/size] [size="2"]wc.lpszMenuName = NULL; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// We Don't Want A Menu[/color][/size][/color][/size] [size="2"]wc.lpszClassName = [/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"OpenGL"[/color][/size][/color][/size][size="2"]; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Set The Class Name[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!RegisterClass(&wc)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Attempt To Register The Window Class[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Failed To Register The Window Class."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (fullscreen) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Attempt Fullscreen Mode?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]DEVMODE dmScreenSettings; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Device Mode[/color][/size][/color][/size] [size="2"]memset(&dmScreenSettings,0,[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]sizeof[/color][/size][/color][/size][size="2"](dmScreenSettings)); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Makes Sure Memory's Cleared[/color][/size][/color][/size] [size="2"]dmScreenSettings.dmSize=[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]sizeof[/color][/size][/color][/size][size="2"](dmScreenSettings); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Size Of The Devmode Structure[/color][/size][/color][/size] [size="2"]dmScreenSettings.dmPelsWidth = width; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Selected Screen Width[/color][/size][/color][/size] [size="2"]dmScreenSettings.dmPelsHeight = height; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Selected Screen Height[/color][/size][/color][/size] [size="2"]dmScreenSettings.dmBitsPerPel = bits; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Selected Bits Per Pixel[/color][/size][/color][/size] [size="2"]dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)[/size] [size="2"]{[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (MessageBox(NULL,[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?"[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"NeHe GL"[/color][/size][/color][/size][size="2"],MB_YESNO|MB_ICONEXCLAMATION)==IDYES)[/size] [size="2"]{[/size] [size="2"]fullscreen=FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windowed Mode Selected. Fullscreen = FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Pop Up A Message Box Letting User Know The Program Is Closing.[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Program Will Now Close."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONSTOP);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (fullscreen) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Still In Fullscreen Mode?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]dwExStyle=WS_EX_APPWINDOW; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Extended Style[/color][/size][/color][/size] [size="2"]dwStyle=WS_POPUP; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windows Style[/color][/size][/color][/size] [size="2"]ShowCursor(FALSE); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Hide Mouse Pointer[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Extended Style[/color][/size][/color][/size] [size="2"]dwStyle=WS_OVERLAPPEDWINDOW; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windows Style[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Adjust Window To True Requested Size[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Create The Window[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!(hWnd=CreateWindowEx( dwExStyle, [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Extended Style For The Window[/color][/size][/color][/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"OpenGL"[/color][/size][/color][/size][size="2"], [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Class Name[/color][/size][/color][/size] [size="2"]title, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Title[/color][/size][/color][/size] [size="2"]dwStyle | [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Defined Window Style[/color][/size][/color][/size] [size="2"]WS_CLIPSIBLINGS | [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Required Window Style[/color][/size][/color][/size] [size="2"]WS_CLIPCHILDREN, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Required Window Style[/color][/size][/color][/size] [size="2"]0, 0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Window Position[/color][/size][/color][/size] [size="2"]WindowRect.right-WindowRect.left, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Calculate Window Width[/color][/size][/color][/size] [size="2"]WindowRect.bottom-WindowRect.top, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Calculate Window Height[/color][/size][/color][/size] [size="2"]NULL, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Parent Window[/color][/size][/color][/size] [size="2"]NULL, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Menu[/color][/size][/color][/size] [size="2"]hInstance, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Instance[/color][/size][/color][/size] [size="2"]NULL))) [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Dont Pass Anything To WM_CREATE[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Window Creation Error."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]static[/color][/size][/color][/size][size="2"] PIXELFORMATDESCRIPTOR pfd= [/size][size="2"][color="#008000"][size="2"][color="#008000"]// pfd Tells Windows How We Want Things To Be[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]sizeof[/color][/size][/color][/size][size="2"](PIXELFORMATDESCRIPTOR), [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Size Of This Pixel Format Descriptor[/color][/size][/color][/size] [size="2"]1, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Version Number[/color][/size][/color][/size] [size="2"]PFD_DRAW_TO_WINDOW | [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Format Must Support Window[/color][/size][/color][/size] [size="2"]PFD_SUPPORT_OPENGL | [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Format Must Support OpenGL[/color][/size][/color][/size] [size="2"]PFD_DOUBLEBUFFER, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Must Support Double Buffering[/color][/size][/color][/size] [size="2"]PFD_TYPE_RGBA, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Request An RGBA Format[/color][/size][/color][/size] [size="2"]bits, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Select Our Color Depth[/color][/size][/color][/size] [size="2"]0, 0, 0, 0, 0, 0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Color Bits Ignored[/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Alpha Buffer[/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Shift Bit Ignored[/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Accumulation Buffer[/color][/size][/color][/size] [size="2"]0, 0, 0, 0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Accumulation Bits Ignored[/color][/size][/color][/size] [size="2"]16, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// 16Bit Z-Buffer (Depth Buffer) [/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Stencil Buffer[/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// No Auxiliary Buffer[/color][/size][/color][/size] [size="2"]PFD_MAIN_PLANE, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Main Drawing Layer[/color][/size][/color][/size] [size="2"]0, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reserved[/color][/size][/color][/size] [size="2"]0, 0, 0 [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Layer Masks Ignored[/color][/size][/color][/size] [size="2"]};[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!(hDC=GetDC(hWnd))) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Did We Get A Device Context?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Can't Create A GL Device Context."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Did Windows Find A Matching Pixel Format?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Can't Find A Suitable PixelFormat."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](!SetPixelFormat(hDC,PixelFormat,&pfd)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Set The Pixel Format?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Can't Set The PixelFormat."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!(hRC=wglCreateContext(hDC))) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Are We Able To Get A Rendering Context?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Can't Create A GL Rendering Context."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](!wglMakeCurrent(hDC,hRC)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Try To Activate The Rendering Context[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Can't Activate The GL Rendering Context."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]ShowWindow(hWnd,SW_SHOW); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Show The Window[/color][/size][/color][/size] [size="2"]SetForegroundWindow(hWnd); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Slightly Higher Priority[/color][/size][/color][/size] [size="2"]SetFocus(hWnd); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets Keyboard Focus To The Window[/color][/size][/color][/size] [size="2"]ReSizeGLScene(width, height); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set Up Our Perspective GL Screen[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!InitGL()) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Initialize Our Newly Created GL Window[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Reset The Display[/color][/size][/color][/size] [size="2"]MessageBox(NULL,[/size] [size="2"][color="#a31515"][size="2"][color="#a31515"]"Initialization Failed."[/color][/size][/color][/size][size="2"],[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"ERROR"[/color][/size][/color][/size][size="2"],MB_OK|MB_ICONEXCLAMATION);[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] FALSE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return FALSE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] TRUE; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Success[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]LRESULT CALLBACK WndProc( HWND hWnd, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Handle For This Window[/color][/size][/color][/size] [size="2"]UINT uMsg, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Message For This Window[/color][/size][/color][/size] [size="2"]WPARAM wParam, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Additional Message Information[/color][/size][/color][/size] [size="2"]LPARAM lParam) [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Additional Message Information[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]switch[/color][/size][/color][/size][size="2"] (uMsg) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Check For Windows Messages[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_ACTIVATE: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Watch For Window Activate Message[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!HIWORD(wParam)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Check Minimization State[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]active=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Program Is Active[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Otherwise[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]active=FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Program Is No Longer Active[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Return To The Message Loop[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_SYSCOMMAND: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Intercept System Commands[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]switch[/color][/size][/color][/size][size="2"] (wParam) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Check System Calls[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] SC_SCREENSAVE: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Screensaver Trying To Start?[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] SC_MONITORPOWER: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Monitor Trying To Enter Powersave?[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Prevent From Happening[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]break[/color][/size][/color][/size][size="2"]; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Exit[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_CLOSE: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Did We Receive A Close Message?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]PostQuitMessage(0); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Send A Quit Message[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Jump Back[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_KEYDOWN: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is A Key Being Held Down?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]keys[wParam] = TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If So, Mark It As TRUE[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Jump Back[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_KEYUP: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Has A Key Been Released?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]keys[wParam] = FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If So, Mark It As FALSE[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Jump Back[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]case[/color][/size][/color][/size][size="2"] WM_SIZE: [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Resize The OpenGL Window[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// LoWord=Width, HiWord=Height[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Jump Back[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Pass All Unhandled Messages To DefWindowProc[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] DefWindowProc(hWnd,uMsg,wParam,lParam);[/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size] [size="2"]WINAPI WinMain( HINSTANCE hInstance, [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Instance[/color][/size][/color][/size] [size="2"]HINSTANCE hPrevInstance, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Previous Instance[/color][/size][/color][/size] [size="2"]LPSTR lpCmdLine, [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Command Line Parameters[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] nCmdShow) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Window Show State[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]MSG msg; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windows Message Structure[/color][/size][/color][/size] [size="2"]BOOL done=FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Bool Variable To Exit Loop[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Ask The User Which Screen Mode They Prefer[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (MessageBox(NULL,[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"Would You Like To Run In Fullscreen Mode?"[/color][/size][/color][/size][size="2"], [/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"Start FullScreen?"[/color][/size][/color][/size][size="2"],MB_YESNO|MB_ICONQUESTION)==IDNO)[/size] [size="2"]{[/size] [size="2"]fullscreen=FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Windowed Mode[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Create Our OpenGL Window[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!CreateGLWindow([/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"Piotr Cieslak & NeHe's Morphing Points Tutorial"[/color][/size][/color][/size][size="2"],640,480,16,fullscreen))[/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Quit If Window Was Not Created[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]while[/color][/size][/color][/size][size="2"](!done) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Loop That Runs While done=FALSE[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is There A Message Waiting?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (msg.message==WM_QUIT) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Have We Received A Quit Message?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]done=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If So done=TRUE[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If Not, Deal With Window Messages[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]TranslateMessage(&msg); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Translate The Message[/color][/size][/color][/size] [size="2"]DispatchMessage(&msg); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Dispatch The Message[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If There Are No Messages[/color][/size][/color][/size] [size="2"]{[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (active && keys[VK_ESCAPE]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Active? Was There A Quit Received?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]done=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// ESC or DrawGLScene Signalled A Quit[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]else[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Not Time To Quit, Update Screen[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]DrawGLScene(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Draw The Scene (Don't Draw When Inactive 1% CPU Use)[/color][/size][/color][/size] [size="2"]SwapBuffers(hDC); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Swap Buffers (Double Buffering)[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_PRIOR]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Page Up Being Pressed?[/color][/size][/color][/size] [size="2"]zspeed+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Increase zspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_NEXT]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Page Down Being Pressed?[/color][/size][/color][/size] [size="2"]zspeed-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Decrease zspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_DOWN]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Down Arrow Being Pressed?[/color][/size][/color][/size] [size="2"]xspeed+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Increase xspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_UP]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Up Arrow Being Pressed?[/color][/size][/color][/size] [size="2"]xspeed-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Decrease xspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_RIGHT]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Right Arrow Being Pressed?[/color][/size][/color][/size] [size="2"]yspeed+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Increase yspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keys[VK_LEFT]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Left Arrow Being Pressed?[/color][/size][/color][/size] [size="2"]yspeed-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Decrease yspeed[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'Q'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Q Key Being Pressed?[/color][/size][/color][/size] [size="2"]cz-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Away From Viewer[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'Z'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is Z Key Being Pressed?[/color][/size][/color][/size] [size="2"]cz+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Towards Viewer[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'W'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is W Key Being Pressed?[/color][/size][/color][/size] [size="2"]cy+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Up[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'S'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is S Key Being Pressed?[/color][/size][/color][/size] [size="2"]cy-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Down[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'D'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is D Key Being Pressed?[/color][/size][/color][/size] [size="2"]cx+=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Right[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'A'[/color][/size][/color][/size][size="2"]]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is A Key Being Pressed?[/color][/size][/color][/size] [size="2"]cx-=0.01f; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Move Object Left[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'1'[/color][/size][/color][/size][size="2"]] && (key!=1) && !morph) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is 1 Pressed, key Not Equal To 1 And Morph False?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]key=1; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets key To 1 (To Prevent Pressing 1 2x In A Row)[/color][/size][/color][/size] [size="2"]morph=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set morph To True (Starts Morphing Process)[/color][/size][/color][/size] [size="2"]dest=&morph1; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Destination Object To Morph To Becomes morph1[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'2'[/color][/size][/color][/size][size="2"]] && (key!=2) && !morph) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is 2 Pressed, key Not Equal To 2 And Morph False?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]key=2; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets key To 2 (To Prevent Pressing 2 2x In A Row)[/color][/size][/color][/size] [size="2"]morph=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set morph To True (Starts Morphing Process)[/color][/size][/color][/size] [size="2"]dest=&morph2; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Destination Object To Morph To Becomes morph2[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'3'[/color][/size][/color][/size][size="2"]] && (key!=3) && !morph) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is 3 Pressed, key Not Equal To 3 And Morph False?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]key=3; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets key To 3 (To Prevent Pressing 3 2x In A Row)[/color][/size][/color][/size] [size="2"]morph=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set morph To True (Starts Morphing Process)[/color][/size][/color][/size] [size="2"]dest=&morph3; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Destination Object To Morph To Becomes morph3[/color][/size][/color][/size] [size="2"]}[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'4'[/color][/size][/color][/size][size="2"]] && (key!=4) && !morph) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is 4 Pressed, key Not Equal To 4 And Morph False?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]key=4; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Sets key To 4 (To Prevent Pressing 4 2x In A Row)[/color][/size][/color][/size] [size="2"]morph=TRUE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Set morph To True (Starts Morphing Process)[/color][/size][/color][/size] [size="2"]dest=&morph4; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Destination Object To Morph To Becomes morph4[/color][/size][/color][/size] [size="2"]}[/size] [color=#FF0000][size="2"][size="2"]if[/size][/size][size="2"] (keys[[/size][size="2"][size="2"]'5'[/size][/size][size="2"]] && (key!=5) && !morph)[/size][/color] [color=#FF0000][size="2"]{[/size][/color] [color=#FF0000][size="2"]key=5;[/size][/color] [color=#FF0000][size="2"]morph=TRUE;[/size][/color] [color=#FF0000][size="2"]dest=&morph5;[/size][/color] [color=#FF0000][size="2"]}[/size][/color] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (keys[VK_F1]) [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Is F1 Being Pressed?[/color][/size][/color][/size] [size="2"]{[/size] [size="2"]keys[VK_F1]=FALSE; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// If So Make Key FALSE[/color][/size][/color][/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Kill Our Current Window[/color][/size][/color][/size] [size="2"]fullscreen=!fullscreen; [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Toggle Fullscreen / Windowed Mode[/color][/size][/color][/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Recreate Our OpenGL Window[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"] (!CreateGLWindow([/size][size="2"][color="#a31515"][size="2"][color="#a31515"]"Piotr Cieslak & NeHe's Morphing Points Tutorial"[/color][/size][/color][/size][size="2"],640,480,16,fullscreen))[/size] [size="2"]{[/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] 0; [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Quit If Window Was Not Created[/color][/size][/color][/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"]}[/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Shutdown[/color][/size][/color][/size] [size="2"]KillGLWindow(); [/size] [size="2"][color="#008000"][size="2"][color="#008000"]// Kill The Window[/color][/size][/color][/size] [size="2"][color="#0000ff"][size="2"][color="#0000ff"]return[/color][/size][/color][/size][size="2"] (msg.wParam); [/size][size="2"][color="#008000"][size="2"][color="#008000"]// Exit The Program[/color][/size][/color][/size] [size="2"]}[/size] [size=5][color=#FF0000][b]// When I run the code as is above all other objects appear and morph properly but when I press the '5' key in an attempt to morph to the object by reading the file of vertices (that I copied from one of the originals) it gives me an error [/b][/color][b]"Unhandled exception at 0x004370cf in Lesson25.exe: 0xC0000005: Access violation reading location 0x00000000." [color="#ff0000"]And it places an arrow at the line[/color][/b][/size] [size=5][b]"a.x=(sour->points[i].x-dest->points[i].x)/steps;" [color=#FF0000]If you could help it would be greatly appreciated!![/color][/b][/size]