heres the code:
my problem is, it compiles just fine, but when I run it, it says that it has commited an error, and I dont know what it is.Code:#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 #include <gl\glaux.h> // Header File For The Glaux Library #define MAX_PARTICLES 1000 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 float slowdown = 2.0f; 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 struct PARTICLE { bool active; // is particle alive? float life; // how much life does particle have float fade; // how fast does it die out float x; // its x pos float y; // its y pos float z; // its z pos float xvec; // its x vector float yvec; // its y vector float zvec; // its z vector float xgrav; // its gravity on x plane float ygrav; // its gravity on y plane float zgrav; // its gravity on z plane float r; // its red color float g; // its green color float b; // its blue color }; PARTICLE particle[MAX_PARTICLES]; 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) // Prevent A Divide By Zero By { height=1; // Making Height Equal One } glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio 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 { glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_BLEND); // Enable Blending glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Type Of Blending To Perform glDisable(GL_DEPTH_TEST); // Disables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations for (int loop = 0; loop < MAX_PARTICLES;loop++) { particle[loop].active = TRUE; // initiating particles life; particle[loop].life = 1.0f; // initiating particle's life time particle[loop].fade = float(((rand() % loop)/1000) + .003f); // set a random fading time particle[loop].xvec = float((rand() % 100) - 50.0f) * 10.0f; // randome velocity on x vector particle[loop].yvec = float((rand() % 100) - 50.0f) * 10.0f; // randome velocity on y vector particle[loop].zvec = float((rand() % 100) - 50.0f) * 10.0f; // randome velocity on z vector particle[loop].xgrav = 0.0f; particle[loop].ygrav = -0.8f; particle[loop].zgrav = 0.0f; particle[loop].r = float(((rand() % 100)/1000) * slowdown); particle[loop].g = float(((rand() % 100)/1000) * slowdown); particle[loop].b = float(((rand() % 100)/1000) * slowdown); } return TRUE; // Initialization Went OK } int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix for (int loop = 0; loop<MAX_PARTICLES;loop++) { if (particle[loop].active) { float x = particle[loop].x; float y = particle[loop].y; float z = particle[loop].z; glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life); glBegin(GL_TRIANGLES); glVertex3f(x+0.5f,y+0.5f,z); glVertex3f(x-0.5f,y+0.5f,z); glVertex3f(x+0.5f,y-0.5f,z); glEnd(); particle[loop].x += particle[loop].xvec/(slowdown*1000); particle[loop].y += particle[loop].yvec/(slowdown*1000); particle[loop].z += particle[loop].zvec/(slowdown*1000); particle[loop].xvec += particle[loop].xgrav; particle[loop].yvec += particle[loop].ygrav; particle[loop].xvec += particle[loop].zgrav; particle[loop].life -= particle[loop].fade; if (particle[loop].life < 0.0f) { particle[loop].life = 1.0f; particle[loop].fade = float(rand()%100)/1000.0f+0.003f; particle[loop].x = 0.0f; particle[loop].y = 0.0f; particle[loop].z = 0.0f; particle[loop].xvec = float(((rand() % 100)/100) + .05f); particle[loop].yvec = float(((rand() % 100)/100) + .05f); particle[loop].zvec = float(((rand() % 100)/100) + .05f); particle[loop].r = float(((rand() % 100)/1000) * slowdown); particle[loop].g = float(((rand() % 100)/1000) * slowdown); particle[loop].b = float(((rand() % 100)/1000) * slowdown); } } } return TRUE; } ................everything the same as NeHe's base code



LinkBack URL
About LinkBacks


