🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Help me please!
I have just written a firework program and fixed all bugs but the result is not what i want:
-The scene i imagine: Some fireworks going from the bottom of the screen and then explode.
-The scene i get: A black screen and a white particle blinking in the bottom of the screen.
I have looked at my code carefully but still can't find the reason, can someone tell me the possible reasons for my unwanted results?
Thanks alot. :)
at this point you will have to post the parts of you code which you think are relevant to displaying the fireworks, and we can look for obvious oversights in that code. Use the tags (without the space) to put source code into a post on game dev.
Oh yes, here is the section of code i think it is relevant to displaying the fireworks: (i am really sorry because you have to look at the code of a beginner like this :( )
And this section i put in the WINAPI WinMain:
And here is the link the my full program, i wrote it based on Nehe's lesson 19.
http://www.4shared.com/file/14133318/e2d0a749/Lesson19.html
[Edited by - ChipChip on April 15, 2007 10:13:01 AM]
typedef struct float r,g,b; // Particle's Colors float x,y,z; // Particle's Position float xi,yi,zi; // Particle's Movement}particle; // Particles Structuretypedef struct // Create A Structure For Firework{ float x,y; // Firework's Position float xi,yi; // Firework's Movement particle body[BODY_PARTICLES]; // Body of Firework particle tail[TAIL_PARTICLES]; // Tail of Firework int starttime; // Time the firework was set int duration; // How long it will last int style; // Picture it should create}Firework;Firework Fireworks[10];void SetupFirework(int i) // Setup the new firework variables{ int clr; float rnum; clr=rand()%3; Fireworks.starttime=ElapsedTime; Fireworks.duration=rand()%1000+3000; Fireworks.x=1.0f*(rand()%20-10); Fireworks.y=-20.0f; Fireworks.xi =(rand()*2-1)/80.0f; Fireworks.yi =(rand()+1.5f)/80.0f; Fireworks.style =rand()%10; for (loop=0;loop<BODY_PARTICLES;loop++) // Initials All The Textures { if (Fireworks.style < 2) { rnum = (rand()/6.0f +0.4f)/10.0f*EXPLOSION_SIZE; } else { rnum = (rand()/10.0f -0.05f)*EXPLOSION_SIZE; } Fireworks.body[loop].xi =rnum* cos(loop/10.0f); Fireworks.body[loop].yi =rnum* sin(loop/10.0f); Fireworks.body[loop].zi =rnum* cos(loop/4.0f); Fireworks.body[loop].x =Fireworks.body[loop].xi; Fireworks.body[loop].y =Fireworks.body[loop].yi; Fireworks.body[loop].z =Fireworks.body[loop].zi; if (clr == 0) Fireworks.body[loop].r =rand()/3.0f + 0.7f; else Fireworks.body[loop].r =rand()/3.0f + 0.4f; if (clr == 1) Fireworks.body[loop].g =rand()/3.0f + 0.7f; else Fireworks.body[loop].g =rand()/3.0f + 0.4f; if (clr == 2) Fireworks.body[loop].b =rand()/3.0f + 0.7f; else Fireworks.body[loop].b =rand()/3.0f + 0.4f; } for (loop=0;loop<TAIL_PARTICLES;loop++) { Fireworks.tail[loop].x=0.0f; Fireworks.tail[loop].y=0.0f; Fireworks.tail[loop].z= 50.0f + rand()%50; // will act as duration for particle Fireworks.tail[loop].xi=-0.7f*Fireworks.xi; Fireworks.tail[loop].yi=-rand()/20-0.001f; if (clr == 0) Fireworks.tail[loop].r =rand()/3.0f + 0.8f; else Fireworks.tail[loop].r =rand()/3.0f + 0.4f; if (clr == 1) Fireworks.tail[loop].g =rand()/3.0f + 0.8f; else Fireworks.tail[loop].g =rand()/3.0f + 0.4f; if (clr == 2) Fireworks.tail[loop].b =rand()/3.0f + 0.8f; else Fireworks.tail[loop].b =rand()/3.0f + 0.4f; }}void FireworkTail(int i){ int j; glTranslatef(Fireworks.x, Fireworks.y, 0); // the main part of the rocket glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); // the tail of the rocket glBegin(GL_QUADS); for (j=0;j<TAIL_PARTICLES;j++) { glColor4f(Fireworks.tail[j].r, Fireworks.tail[j].g, Fireworks.tail[j].b, Fireworks.tail[j].z/100.0f); // here Z is used as the alpha value glTexCoord2f(0.0f, 0.0f); glVertex3f(Fireworks.tail[j].x-1.0f, Fireworks.tail[j].y-1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(Fireworks.tail[j].x+1.0f, Fireworks.tail[j].y-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(Fireworks.tail[j].x+1.0f, Fireworks.tail[j].y+1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(Fireworks.tail[j].x-1.0f, Fireworks.tail[j].y+1.0f, 0.0f); Fireworks.tail[j].x =Fireworks.tail[j].x+Fireworks.tail[j].xi; Fireworks.tail[j].y =Fireworks.tail[j].y+Fireworks.tail[j].yi; Fireworks.tail[j].z =Fireworks.tail[j].z-1; if (Fireworks.tail[j].z == 0.0f) { Fireworks.tail[j].x = 0.0f; Fireworks.tail[j].y = 0.0f; Fireworks.tail[j].z =50.0f + rand()%50; } } glEnd();}void FireworkExplode(int i){ int j; float slowdown; glTranslatef(Fireworks.x, Fireworks.y, 0.0f); glBegin(GL_QUADS); for (j=0;j<BODY_PARTICLES;j++) { glColor4f(Fireworks.body[j].r, Fireworks.body[j].g, Fireworks.body[j].b, 1.8f-(ElapsedTime-Fireworks.starttime-1000)/1200.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(Fireworks.body[j].x-1.0f, Fireworks.body[j].y-1.0f, Fireworks.body[j].z); glTexCoord2f(1.0f, 0.0f); glVertex3f(Fireworks.body[j].x+1.0f, Fireworks.body[j].y-1.0f, Fireworks.body[j].z); glTexCoord2f(1.0f, 1.0f); glVertex3f(Fireworks.body[j].x+1.0f, Fireworks.body[j].y+1.0f, Fireworks.body[j].z); glTexCoord2f(0.0f, 1.0f); glVertex3f(Fireworks.body[j].x-1.0f, Fireworks.body[j].y+1.0f, Fireworks.body[j].z); // Calculate the new coords based on the change, dX, in a direction // and slow the change down as time goes by. slowdown =((ElapsedTime-Fireworks.starttime-1000) - pow((float)(1000+Fireworks.starttime-ElapsedTime),2)/5000.0f)/6.0f; Fireworks.body[j].x =Fireworks.body[j].xi * slowdown; Fireworks.body[j].y =Fireworks.body[j].yi * slowdown; Fireworks.body[j].z =Fireworks.body[j].zi * slowdown; } glEnd(); }void glDraw(){ int i; float slowdown; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0,0.0,-50.0f); for (i=0;i<= nFireworks-1;i++) { glPushMatrix(); // Display the firework if (ElapsedTime-Fireworks.starttime < 1000) { FireworkTail(i); } else { FireworkExplode(i); } // create a new firework if (ElapsedTime - Fireworks.starttime - Fireworks.duration >=0) { SetupFirework(i); } // keep moving and slowing down firework slowdown =pow((float)(Fireworks.starttime-ElapsedTime),2); Fireworks.x =Fireworks.xi * ((ElapsedTime-Fireworks.starttime) - slowdown/7000.0f); Fireworks.y =Fireworks.yi * ((ElapsedTime-Fireworks.starttime) - slowdown/4500.0f) - 20.0f; glPopMatrix(); }}int InitGL(GLvoid) // All Setup For OpenGL Goes Here{ int i; if (!LoadGLTextures()) // Jump To Texture Loading Routine { return FALSE; // If Texture Didn't Load Return FALSE } glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f,0.0f,0.0f,0.0f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glDisable(GL_DEPTH_TEST); // Disable Depth Testing glEnable(GL_BLEND); // Enable Blending glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Type Of Blending To Perform glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // Really Nice Perspective Calculations glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); // Really Nice Point Smoothing glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glBindTexture(GL_TEXTURE_2D,texture[0]); // Select Our Texture nFireworks=3; for (i=0;i<=nFireworks-1;i++) { SetupFirework(i); Fireworks.starttime=-1000*i; } return TRUE; // Initialization Went OK}
And this section i put in the WINAPI WinMain:
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 DWORD DemoStart, LastTime; DemoStart = GetTickCount(); // Get Time when demo started // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow("Da Great Firework Show",640,480,16,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 { LastTime =ElapsedTime; ElapsedTime =GetTickCount() - DemoStart; // Calculate Elapsed Time ElapsedTime =(LastTime + ElapsedTime) / 2; // Average it out for smoother movement glDraw(); // Draw the scene SwapBuffers(hDC); // Display the scene // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if (keys[VK_ESCAPE]) // Active? Was There A Quit Received? { done=TRUE; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1]=FALSE; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow("Da Great Firework Show",640,480,32,fullscreen)) { return 0; // Quit If Window Was Not Created } } } } } // Shutdown KillGLWindow(); // Kill The Window return (msg.wParam); // Exit The Program}
And here is the link the my full program, i wrote it based on Nehe's lesson 19.
http://www.4shared.com/file/14133318/e2d0a749/Lesson19.html
[Edited by - ChipChip on April 15, 2007 10:13:01 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement