I have to make a simple 3d game.
The game scenario consists of a spacecraft that is attacking the home planet
by firing rockets from along its length randomly. The game player moves the
baton up and down to stop the rockets before they reach the planet.
The star field behind the main scene should drift slowly from bottom to top
with new stars appearing from the bottom as the old stars disappear from the
I have manage to draw the planet and the stars but, but need help with the stars to move from bottom to top, and need help to draw a spaceship firing rockets the spaceship.Rockets and the spacecraft can be built of either triangular faces or
quadrics or a mix of both.

here's my code plz help me to draw the spaceship firing rockets as i have no idea how to draw it.

#include "shared/gltools.h" // OpenGL toolkit
#include "shared/MathsUtils.h" // Mathematical toolkit
#include <string.h>

#define X_CENTRE 0.00    // centre point of co-ordinate system //
#define Y_CENTRE 0.00
#define Z_CENTRE 0.00
#define WIDTH 100       //X-max
#define HEIGHT -100 
float STEP = 00.0;      //Float used for Shield Y-axis translation amount

Point*points;                               //Array used to create "star" points. X Column and Y row

float starTranslation = -100.00;

void *font = GLUT_BITMAP_TIMES_ROMAN_24;

void output(int x, int y, char *string)
    int len,i;
    len = (int) strlen(string);
    for(i= 0; i<len; i++){
        glutBitmapCharacter(font, string[i]);

void keyboard(unsigned char key, int x, int y)

    switch (key)
    case 'p':   //P-key is pressed
                STEP = STEP + 5.0;//Shield moves up the X-axis by 5.0
    case 'l':   //L-key is pressed          
                STEP = STEP - 5.0;//Shield moves down the X-axis by 5.0
    default: break;//Any other key, do nothing


void createRandomStarArray(int numOfStars,float xMin,float xMax, float yMin,float yMax, float zMin, float zMax)

         //Create a random array of points
         //first seed the random generator
          //instantiate an array of points
          points = new Point[numOfStars];
//xScope and yScope are the full absolute width of the screen
            int xScope = (int)(abs(xMin) + (abs(xMax)));
            int yScope = (int)(abs(yMin) + (abs(yMax)));
            int zScope = (int)(abs(zMin) + (abs(zMax)));
            for(int index=0; index<numOfStars; index++){ 
        points[index].x = rand()%(xScope)+1.0 - abs(xMin);
        points[index].y = rand()%(yScope)+1.0 - abs(yMin);
        points[index].z = rand()%(zScope)+1.0 - abs(zMin);
        glColor3ub(200, 200, 200); //white colour for the stars

        glVertex3f(points[index].x, points[index].y, points[index].z);          


void reshape(int width, int height)
    glViewport(0, 0, width, height);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
   /* use orthographic (parallel) projection
      use xmin = -100, xmax = 100
          ymin = -100, ymax = 100*/
    glOrtho(-100, WIDTH, HEIGHT, 100, -100, 100); 
    glMatrixMode( GL_MODELVIEW );

void drawPlanet() // to draw planet
{     //

    glColor3ub(5, 5, 60);     //   Blue Planet Earth
    glutSolidSphere(50, 100, 16);        //25 for Radius and 50 for Sides

void display(void)


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear the window with current clearing color

      glMatrixMode(GL_MODELVIEW);                       // Save the matrix state and do the rotations

    //Function to create stars amount set to 50, parameters set to othographic projection   

    //Move Co-ordinates

    glTranslatef(0.0f, 10.0f, 0.0f);//Original Co-ordinates (0,10)  

   // draw planet
  glTranslatef(0.0, -110, -50.0);//Translate co-ordinantes to the far right, and draw planet
  glPopMatrix();//Reset to Orginal co-ordinates  


/* graphics initialisation */ 
void init(void)
   glClearColor (0.0, 0.0, 0.0, 0.0);                              //window set to colour black


int main(int argc, char** argv)  // blackboard codes..
   glutInit(&argc, argv);    //initialises GLUT and processes any command line arguments 
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);//use double-buffered window and RGBA colour model and depth
   glutInitWindowSize(800, 700);                  //window width and height 800 pixels and width 700  
   glutInitWindowPosition (0, 0);              //window upper left corner at (0, 0) */
   glutCreateWindow ("coursework");
   return 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.