Original Post
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