Skip to main content
gamedev.net
🔒 Locked

Why isn't this code working?

Started by Erik23a86 Aug 29, 2003 at 10:59 AM 5 replies 1k views
Original Post
Erik23a86
Erik23a86
My code is based on lesson 19 of NeHe but I''m using glut. The problem is that if I run the program I don''t get anything on my screen. Could somebody please take a look at my source code and tell me what I''m doing wrong. source code: //--------------------------------------------------------------------------- #pragma hdrstop #include <windows.h> #include <stdio.h> #include <gl/glut.h> #include <gl/glaux.h> #define MAX_PARTICLES 1000 //--------------------------------------------------------------------------- #pragma argsused #pragma comment(lib, "GLaux.lib") struct Particle { bool alife; float life; float fade; float r; float g; float b; float x; float y; float z; float xd; float yd; float zd; float xg; float yg; float zg; } Particles; Particle Particle[1000]; GLuint texture[1]; GLuint loop; #include "texture.h" int init(void) { if(!LoadGLTextures(0,"particle.bmp")) { return FALSE;} glShadeModel(GL_SMOOTH); // Enables smooth shading glClearColor(0.0f,0.0f,0.0f,0.0f); // Black background glClearDepth(1.0f); // Depth buffer setup glDisable(GL_DEPTH_TEST); // Disables 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]); for(loop = 0;loop < MAX_PARTICLES; loop++) { Particle[loop].alife = true; Particle[loop].life = 1.0f; Particle[loop].fade = float(rand()%100)/1000.0f+0.003f; Particle[loop].r = 0.0f; Particle[loop].g = 0.0f; Particle[loop].b = 0.0f; Particle[loop].xd = float(rand()%50)-25.0f; Particle[loop].yd = float(rand()%50)-25.0f; Particle[loop].zd = float(rand()%50)-25.0f; Particle[loop].xg = 0.0f; Particle[loop].yg = 0.8f; Particle[loop].zg = 0.0f; } return TRUE; } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0f, 0.0f, 0.0f); glLoadIdentity(); for (loop = 0;loop < MAX_PARTICLES;loop++) { if (Particle[loop].alife) { 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_TRIANGLE_STRIP); glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); glEnd(); Particle[loop].x += Particle[loop].xd; Particle[loop].y += Particle[loop].yd; Particle[loop].z += Particle[loop].zd; Particle[loop].xd += Particle[loop].xg; Particle[loop].yd += Particle[loop].yg; Particle[loop].zd += Particle[loop].zg; 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].xd = float((rand()%60)-32.0f); Particle[loop].yd = float((rand()%60)-30.0f); Particle[loop].zd = float((rand()%60)-30.0f); } } } glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch(key) { case ''z'': break; case ''x'': break; case''q'': glutPostRedisplay(); break; case''a'': glutPostRedisplay(); break; default: break; } } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(600,340); glutInitWindowPosition(262,162); glutCreateWindow("test"); glutKeyboardFunc(keyboard); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } //--------------------------------------------------------------------------- Thanks
Brother Bob
Brother Bob
Maybe you should add some code to set projection and viewpoint.
Erik23a86
Erik23a86
How do I set another projection and/or viewpoint?

thanks.
Brother Bob
Brother Bob
Well, you already based your code on NeHe's tutorial, so why not look there? About all of them sets a projection and viewpoint. The GLUT demos usually put them in the reshape callback.

edit: The projection usually go in the reshape callback. Viewpoint usually go in the beginning of the display callback.

[edited by - Brother Bob on August 29, 2003 1:08:24 PM]
Erik23a86
Erik23a86
It still doesn''t work. Maybe I didn''t set the projection viewpoint how it surposed to be set so could you give me a code or a example how to set the projection viewpoint the right way?

Thanks
Brother Bob
Brother Bob
The correct projection and modeivew matrix depends entirely on your scene, and how you want to view it. I suggest you compare your program with the tutorial you based your code on, line by line. If that tutorial works, and your code doesn''t, there must be some difference.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.