Results 1 to 2 of 2

Thread: Trouble with simple shooting range.

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    2

    Trouble with simple shooting range.

    This is my first time programming in OpenGL. I am trying to develop a crossbow shooting range which uses arrays to draw each bolt. I am also having trouble developing a crosshair to help with aiming. I will also have to add collision detection and plan to explode targets when they are hit. I would appreciate any helpful input. Thanks!

    Here is my code so far. The CTgaImg is for texturing, and the Vec3 is a struct i modified for future collision detection. The texturing is commented out because it slows the program down too much.

    #include <stdlib.h>
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <GL/glut.h>
    #include <windows.h>

    #include "CTgaImg.h"
    #include "Vec3.h"

    using namespace std;

    float xpos = 0.0, ypos = 0.0, zpos = 0.0, xrot = 0.0, yrot = 0.0, xrotrad = 0.0, yrotrad = 0.0;
    float lastx, lasty;

    float Vo = 0.0;
    float t[20];
    float Xrot[20], Yrot[20], Xrotrad[20], Yrotrad[20];
    int i, k[20];

    //CTgaImg *img1 = new CTgaImg;
    //CTgaImg *img2 = new CTgaImg;
    //CTgaImg *img3 = new CTgaImg;
    //CTgaImg *img4 = new CTgaImg;

    //GLuint texName1;
    //GLuint texName2;
    //GLuint texName3;
    //GLuint texName4;

    GLUquadricObj *quadratic; // Storage for quadratic objects

    // White light sources
    GLfloat white_light_diff0[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat white_light_amb0[] = { 0.3, 0.3, 0.3, 1.0 };
    GLfloat light_posn0[] = { 0.0, 15.0, -25.0, 0.0 };

    GLfloat white_light_diff1[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat white_light_amb1[] = { 0.3, 0.3, 0.3, 1.0 };
    GLfloat light_posn1[] = { 0.0, 18.0, -100.0, 0.0 };

    GLfloat white_light_diff2[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat white_light_amb2[] = { 0.3, 0.3, 0.3, 1.0 };
    GLfloat light_posn2[] = { 0.0, 15.0, -175.0, 0.0 };

    // White spotlight1 :- the spot light points towards the center of the end wall.
    GLfloat spot_posn1[] = { 10.0, 10.0, 0.0, 1. };
    GLfloat spot_direcn1[] = { -10, -10, -200.0, 1. };
    GLfloat spot_spec1[] = { 1.0, 1.0, 1.0, 1. };
    float spot_cutoff1 = 15.;
    float spot_expo1 = 0.0;

    // White spotlight2 :- the spot light points towards the center of the end wall.
    GLfloat spot_posn2[] = { -10.0, 10.0, 0.0, 1. };
    GLfloat spot_direcn2[] = { 10, -10, -200.0, 1. };
    GLfloat spot_spec2[] = { 1.0, 1.0, 1.0, 1. };
    float spot_cutoff2 = 15.;
    float spot_expo2 = 0.0;

    // Floor
    GLfloat mat_diffuse0[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat mat_ambient0[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat mat_specular0[] = { 0.1, 0.1, 0.1, 1.0 };

    // Side walls
    GLfloat mat_diffuse1[] = { 0.0, 0.0, 0.5, 1.0 };
    GLfloat mat_ambient1[] = { 0.0, 0.0, 0.2, 1.0 };
    GLfloat mat_specular1[] = { 0.0, 0.0, 0.2, 1.0 };

    // End walls
    GLfloat mat_diffuse2[] = { 0.0, 0.0, 0.5, 1.0 };
    GLfloat mat_ambient2[] = { 0.0, 0.0, 0.2, 1.0 };
    GLfloat mat_specular2[] = { 0.0, 0.0, 0.2, 1.0 };

    // Ceiling
    GLfloat mat_diffuse3[] = { 0.7, 0.7, 0.7, 1.0 };
    GLfloat mat_ambient3[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat mat_specular3[] = { 0.1, 0.1, 0.1, 1.0 };

    // Targets
    GLfloat mat_diffuse4[] = { 0.8, 0.0, 0.0, 1.0 };
    GLfloat mat_ambient4[] = { 0.2, 0.0, 0.0, 1.0 };
    GLfloat mat_specular4[] = { 0.3, 0.0, 0.0, 1.0 };

    // Bolts
    GLfloat mat_diffuse5[] = { 0.7, 0.7, 0.0, 1.0 };
    GLfloat mat_ambient5[] = { 0.2, 0.2, 0.0, 1.0 };
    GLfloat mat_specular5[] = { 0.3, 0.3, 0.0, 1.0 };

    /*
    struct Plane{ //Plane structure
    Vec3 _Position;
    Vec3 _Normal;
    };
    struct Explosion{ //Explosion structure
    Vec3 _Position;
    float _Alpha;
    float _Scale;
    };
    Plane pl1,pl2,pl3,pl4,pl5,pl6; //The 6 planes of the room
    Explosion ExplosionArray[20]; //Holds up to 20 explosions
    */

    void reshape( int w, int h )
    {
    if (h==0)
    {
    h=1;
    }

    glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    gluPerspective(60.0f,(GLfloat)w/(GLfloat)h,0.1f,210.0f);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glutPostRedisplay();
    }

    void camera (void)
    {
    glRotatef(xrot,1.0,0.0,0.0); //rotate camera around the x-axis (up and down)
    glRotatef(yrot,0.0,1.0,0.0); //rotate camera around the y-axis (left and right)
    glTranslated(-xpos, -6,-zpos); //translate screen to the position of our camera
    }

    void idle()
    {
    //static int lastUpdate = 0;
    //static int frames = 0;
    //char buf[20];

    glutPostRedisplay();
    glutSwapBuffers();

    //int currentTime = glutGet( GLUT_ELAPSED_TIME );
    //frames++;
    /*
    if ( ( currentTime - lastUpdate ) >= 1000/60 )
    {
    sprintf( buf, "Shooting Range FPS: %d", frames );
    glutSetWindowTitle( buf );
    frames = 0;
    lastUpdate = currentTime;
    }
    */
    }

    void keyboard (unsigned char key, int x, int y)
    {
    float yrotrad = (yrot / 180 * 3.141592654f);
    float xrotrad = (xrot / 180 * 3.141592654f);

    if (key=='q')
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key=='z')
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }

    if (key=='w')
    {
    xpos += float(sin(yrotrad));
    zpos -= float(cos(yrotrad));
    //ypos -= float(sin(xrotrad));
    }

    if (key=='s')
    {
    xpos -= float(sin(yrotrad));
    zpos += float(cos(yrotrad));
    //ypos += float(sin(xrotrad));
    }

    if (key=='d')
    {
    xpos += float(cos(yrotrad)) * 0.5;
    zpos += float(sin(yrotrad)) * 0.5;
    }

    if (key=='a')
    {
    xpos -= float(cos(yrotrad)) * 0.5;
    zpos -= float(sin(yrotrad)) * 0.5;
    }

    if (key=='c')
    {
    yrot = 0;
    xrot = 0;
    xpos = 0;
    zpos = 0;
    ypos = 6;
    SetCursorPos( 639, 509 );
    }

    glutPostRedisplay();
    }

    void mouseMovement(int x, int y)
    {
    if( lastx==0 &amp;&amp; lasty==0 )
    {
    lastx = x;
    lasty = y;
    }
    else
    {
    float diffx = x - lastx;
    float diffy = y - lasty;
    lastx = x;
    lasty = y;
    xrot += (float) diffy;
    yrot += (float) diffx;
    }

    glutPostRedisplay();
    }

    void mouse(int button, int state, int x, int y)
    {
    if( button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN )
    {
    i++;
    k[i] = 1;
    Xrot[i] = xrot;
    Yrot[i] = yrot;
    }

    if( button == GLUT_RIGHT_BUTTON &amp;&amp; state == GLUT_DOWN )
    glutMotionFunc( mouseMovement );
    lastx = 0;
    lasty = 0;
    }

    void drawTarget( float X, float Y, float Z )
    {
    //glBindTexture( GL_TEXTURE_2D, texName4 );
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient4 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse4 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular4 );

    glPushMatrix();
    glTranslatef( X, Y, Z );
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, 1.0 );
    glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0, -1.0, 0.0 );
    glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0, -1.0, 0.0 );
    glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0, 1.0, 0.0 );
    glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0, 1.0, 0.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, -1.0 );
    glVertex3f( -1.0, -1.0, -2.0 );
    glVertex3f( 1.0, -1.0, -2.0 );
    glVertex3f( 1.0, 1.0, -2.0 );
    glVertex3f( -1.0, 1.0, -2.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( -1.0, 0.0, 0.0 );
    glVertex3f( 1.0, -1.0, 0.0 );
    glVertex3f( 1.0, -1.0, -2.0 );
    glVertex3f( 1.0, 1.0, -2.0 );
    glVertex3f( 1.0, 1.0, 0.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 1.0, 0.0, 0.0 );
    glVertex3f( -1.0, -1.0, -2.0 );
    glVertex3f( -1.0, -1.0, 0.0 );
    glVertex3f( -1.0, 1.0, 0.0 );
    glVertex3f( -1.0, 1.0, -2.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    glVertex3f( -1.0, 1.0, 0.0 );
    glVertex3f( 1.0, 1.0, 0.0 );
    glVertex3f( 1.0, 1.0, -2.0 );
    glVertex3f( -1.0, 1.0, -2.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    glVertex3f( -1.0, -1.0, 0.0 );
    glVertex3f( -1.0, -1.0, -2.0 );
    glVertex3f( 1.0, -1.0, -2.0 );
    glVertex3f( 1.0, -1.0, 0.0 );
    glEnd();
    glPopMatrix();

    glDisable( GL_LIGHTING );
    glPopAttrib();
    }

    void shoot(int i)
    {
    //float Yrotrad[i] = (-Yrot[i] / 180 * 3.141592654);
    //float Xrotrad[i] = (-Xrot[i] / 180 * 3.141592654);

    if( k[i]==1 )
    {
    Vo = 5;
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient5 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse5 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular5 );

    glPushMatrix();
    glTranslatef( xpos - Vo*sin(Yrotrad[i])*t[i], 6 + Vo*(Xrotrad[i])*t[i] - 0.025*t[i]*t[i], zpos - Vo*cos(Yrotrad[i])*t[i] );
    glRotatef( -Xrot[i] - 0.5*t[i], cos(Yrotrad[i]), sin(Yrotrad[i]), 0.0 );
    glRotatef( -Yrot[i], 0.0, 1.0, 0.0 );

    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, 1.0 );
    glVertex3f( -0.05, -0.05, 0.0 );
    glVertex3f( 0.05, -0.05, 0.0 );
    glVertex3f( 0.05, 0.05, 0.0 );
    glVertex3f( -0.05, 0.05, 0.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, -1.0 );
    glVertex3f( -0.05, -0.05, -3.0 );
    glVertex3f( 0.05, -0.05, -3.0 );
    glVertex3f( 0.05, 0.05, -3.0 );
    glVertex3f( -0.05, 0.05, -3.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( -1.0, 0.0, 0.0 );
    glVertex3f( 0.05, -0.05, 0.0 );
    glVertex3f( 0.05, -0.05, -3.0 );
    glVertex3f( 0.05, 0.05, -3.0 );
    glVertex3f( 0.05, 0.05, 0.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 1.0, 0.0, 0.0 );
    glVertex3f( -0.05, -0.05, -3.0 );
    glVertex3f( -0.05, -0.05, 0.0 );
    glVertex3f( -0.05, 0.05, 0.0 );
    glVertex3f( -0.05, 0.05, -3.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    glVertex3f( -0.05, 0.05, 0.0 );
    glVertex3f( 0.05, 0.05, 0.0 );
    glVertex3f( 0.05, 0.05, -3.0 );
    glVertex3f( -0.05, 0.05, -3.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    glVertex3f( -0.05, -0.05, 0.0 );
    glVertex3f( -0.05, -0.05, -3.0 );
    glVertex3f( 0.05, -0.05, -3.0 );
    glVertex3f( 0.05, -0.05, 0.0 );
    glEnd();
    glPopMatrix();

    glDisable( GL_LIGHTING );
    glPopAttrib();

    t[i]+=0.025;
    }

    else
    {
    Vo = 0;
    }
    }

    void draw( )
    {

    float yrotrad = (-yrot / 180 * 3.141592654f);
    float xrotrad = (-xrot / 180 * 3.141592654f);

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity();
    camera();

    //gluLookAt( 0.0, 6.0, 0.0, 0.0, 6.0, -200.0, 0.0, 1.0, 0.0 );

    glEnable( GL_NORMALIZE );

    //glBindTexture( GL_TEXTURE_2D, texName1 );
    // Draw right wall
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient1 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse1 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular1 );
    glBegin( GL_POLYGON );
    glNormal3f( -1.0, 0.0, 0.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( 20.0, 0.0, -200.0 );
    /*glTexCoord2f( 5.0f, 0.0f );*/ glVertex3f( 20.0, 0.0, 0.0 );
    /*glTexCoord2f( 5.0f, 1.0f );*/ glVertex3f( 20.0, 20.0, 0.0 );
    /*glTexCoord2f( 0.0f, 1.0f );*/ glVertex3f( 20.0, 20.0, -200.0 );
    glEnd();

    // Draw left wall
    glBegin( GL_POLYGON );
    glNormal3f( 1.0, 0.0, 0.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( -20.0, 0.0, 0.0 );
    /*glTexCoord2f( 5.0f, 0.0f );*/ glVertex3f( -20.0, 0.0, -200.0 );
    /*glTexCoord2f( 5.0f, 1.0f );*/ glVertex3f( -20.0, 20.0, -200.0 );
    /*glTexCoord2f( 0.0f, 1.0f );*/ glVertex3f( -20.0, 20.0, 0.0 );
    glEnd();

    glDisable( GL_LIGHTING );
    glPopAttrib();

    // Draw end walls
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient2 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse2 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular2 );
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, 1.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( -20.0, 0.0, -200. );
    /*glTexCoord2f( 2.0f, 0.0f );*/ glVertex3f( 20.0, 0.0, -200. );
    /*glTexCoord2f( 2.0f, 1.0f );*/ glVertex3f( 20.0, 20.0, -200. );
    /*glTexCoord2f( 0.0f, 1.0f );*/ glVertex3f( -20.0, 20.0, -200.0 );
    glEnd();
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 0.0, 1.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( 20., 0.0, 0.0 );
    /*glTexCoord2f( 2.0f, 0.0f );*/ glVertex3f( 20., 20.0, 0.0 );
    /*glTexCoord2f( 2.0f, 1.0f );*/ glVertex3f( -20., 20.0, 0.0 );
    /*glTexCoord2f( 0.0f, 1.0f );*/ glVertex3f( -20., 0.0, 0.0 );
    glEnd();
    glDisable( GL_LIGHTING );
    glPopAttrib();

    // Draw floor
    //glBindTexture( GL_TEXTURE_2D, texName2 );
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient0 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse0 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular0 );
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( -20.0, 0.0, -200.0 );
    /*glTexCoord2f( 10.0f, 0.0f );*/ glVertex3f( -20.0, 0.0, 0.0 );
    /*glTexCoord2f( 10.0f, 2.0f );*/ glVertex3f( 20.0, 0.0, 0.0 );
    /*glTexCoord2f( 0.0f, 2.0f );*/ glVertex3f( 20.0, 0.0, -200.0 );
    glEnd();
    glDisable( GL_LIGHTING );
    glPopAttrib();

    // Draw ceiling
    //glBindTexture( GL_TEXTURE_2D, texName3 );
    glPushAttrib( GL_LIGHTING );
    glEnable( GL_LIGHTING );
    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient3 );
    glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse3 );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular3 );
    glBegin( GL_POLYGON );
    glNormal3f( 0.0, 1.0, 0.0 );
    /*glTexCoord2f( 0.0f, 0.0f );*/ glVertex3f( -20., 20.0, -200.0 );
    /*glTexCoord2f( 2.0f, 0.0f );*/ glVertex3f( 20., 20.0, -200.0 );
    /*glTexCoord2f( 2.0f, 10.0f );*/ glVertex3f( 20., 20.0, 0.0 );
    /*glTexCoord2f( 0.0f, 10.0f );*/ glVertex3f( -20., 20.0, 0.0 );
    glEnd();
    glDisable( GL_LIGHTING );
    glPopAttrib();

    // Draw targets
    drawTarget( -8.0, 8.0, -50 );
    drawTarget( 0.0, 8.0, -50 );
    drawTarget( 8.0, 8.0, -50 );

    drawTarget( -8.0, 6.0, -150 );
    drawTarget( 0.0, 6.0, -150 );
    drawTarget( 8.0, 6.0, -150 );

    // Draw crosshairs
    glColor3f( 0.0, 1.0, 0.0 );
    glPushMatrix();
    glTranslatef( xpos, 6.0, zpos );
    glRotatef( -yrot, 0.0, 1.0, 0.0 );
    glRotatef( -xrot, cos(yrotrad), sin(yrotrad), 0.0 );
    glTranslatef( 0.0, 0.0, -1.0 );
    glBegin( GL_LINES );
    glVertex3f( -0.02, 0.0, 0.0 );
    glVertex3f( 0.02, 0.0, 0.0 );
    glEnd();
    glBegin( GL_LINES );
    glVertex3f( 0.0, 0.02, 0.0 );
    glVertex3f( 0.0, -0.02, 0.0 );
    glEnd();
    glPopMatrix();

    // Shoot bolt
    shoot(i);

    glutSwapBuffers();
    }

    void init( )
    {
    k[i] = 0;
    t[i] = 0;

    SetCursorPos( 639, 509 );

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

    // Enable depth testing
    glClearDepth( 1.0f );
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );

    glShadeModel( GL_SMOOTH );
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

    // Quadratic shape rendering
    quadratic = gluNewQuadric(); // Create A Pointer To The Quadric Object
    gluQuadricNormals( quadratic, GLU_SMOOTH ); // Create Smooth Normals
    gluQuadricTexture( quadratic, GL_TRUE ); // Create Texture Coords

    // First light is a white light (source at infinity)
    glLightfv( GL_LIGHT0, GL_POSITION, light_posn0 );
    glLightfv( GL_LIGHT0, GL_DIFFUSE, white_light_diff0 );
    glLightfv( GL_LIGHT0, GL_AMBIENT, white_light_amb0 );
    glEnable( GL_LIGHT0 );

    // Second light is a white light (source at infinity)
    glLightfv( GL_LIGHT1, GL_POSITION, light_posn1 );
    glLightfv( GL_LIGHT1, GL_DIFFUSE, white_light_diff1 );
    glLightfv( GL_LIGHT1, GL_AMBIENT, white_light_amb1 );
    glEnable( GL_LIGHT1 );

    // Third light is a white light (source at infinity)
    glLightfv( GL_LIGHT2, GL_POSITION, light_posn2 );
    glLightfv( GL_LIGHT2, GL_DIFFUSE, white_light_diff2 );
    glLightfv( GL_LIGHT2, GL_AMBIENT, white_light_amb2 );
    glEnable( GL_LIGHT2 );

    // First white spotlight
    glLightfv( GL_LIGHT3, GL_DIFFUSE, white_light_diff0 );
    glLightfv( GL_LIGHT3, GL_SPECULAR, spot_spec1 );
    glLightfv( GL_LIGHT3, GL_POSITION, spot_posn1 );
    glLightfv( GL_LIGHT3, GL_SPOT_DIRECTION, spot_direcn1 );
    glLightfv( GL_LIGHT3, GL_SPOT_CUTOFF, &amp;spot_cutoff1 );
    glLightfv( GL_LIGHT3, GL_SPOT_EXPONENT, &amp;spot_expo1 );
    glEnable( GL_LIGHT3 );

    // Second white spotlight
    glLightfv( GL_LIGHT4, GL_DIFFUSE, white_light_diff0 );
    glLightfv( GL_LIGHT4, GL_SPECULAR, spot_spec2 );
    glLightfv( GL_LIGHT4, GL_POSITION, spot_posn2 );
    glLightfv( GL_LIGHT4, GL_SPOT_DIRECTION, spot_direcn2 );
    glLightfv( GL_LIGHT4, GL_SPOT_CUTOFF, &amp;spot_cutoff2 );
    glLightfv( GL_LIGHT4, GL_SPOT_EXPONENT, &amp;spot_expo2 );
    glEnable( GL_LIGHT4 );

    /*
    //Texturing
    glEnable( GL_TEXTURE_2D );
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    // Read in texture1
    std::cout << img1->loadTGAImg("bunkerwall.tga") << "\n";

    glGenTextures( 1, &amp;texName1 );
    glBindTexture( GL_TEXTURE_2D, texName1 );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, img1->getImgWidth(), img1->getImgHeight(),
    0, GL_RGB, GL_UNSIGNED_BYTE , img1->getImgPixelData() );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    // Read in texture2
    std::cout << img2->loadTGAImg("concretetile.tga") << "\n";

    glGenTextures( 1, &amp;texName2 );
    glBindTexture( GL_TEXTURE_2D, texName2 );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, img2->getImgWidth(), img2->getImgHeight(),
    0, GL_RGB, GL_UNSIGNED_BYTE , img2->getImgPixelData() );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    // Read in texture3
    std::cout << img3->loadTGAImg("concrete.tga") << "\n";

    glGenTextures( 1, &amp;texName3 );
    glBindTexture( GL_TEXTURE_2D, texName3 );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, img3->getImgWidth(), img3->getImgHeight(),
    0, GL_RGB, GL_UNSIGNED_BYTE , img2->getImgPixelData() );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    // Read in texture4
    glEnable( GL_TEXTURE_2D );
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    std::cout << img4->loadTGAImg("target.tga") << "\n";

    glGenTextures( 1, &amp;texName4 );
    glBindTexture( GL_TEXTURE_2D, texName4 );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, img4->getImgWidth(), img4->getImgHeight(),
    0, GL_RGB, GL_UNSIGNED_BYTE , img4->getImgPixelData() );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    */
    }

    int main( int argc, char* argv[] )
    {
    glutInit( &amp;argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowPosition( 0, 0 );
    glutInitWindowSize( 1270, 960 );
    glutCreateWindow( "Shooting Range" );

    glutSetCursor( GLUT_CURSOR_CROSSHAIR );

    init();
    glutDisplayFunc( draw );
    glutReshapeFunc( reshape );
    glutMouseFunc( mouse );
    glutKeyboardFunc( keyboard );
    glutIdleFunc( idle );
    glutMainLoop();

    return 0;
    }

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Trouble with simple shooting range.

    If you ask a single simple specific question you are more likely to get an answer.

    If providing code please keep it concise and relevant to the specific question.

Similar Threads

  1. having trouble with simple program
    By Craz1000 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-11-2009, 12:55 PM
  2. Help with simple shooting range
    By pcormier9988 in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 07-20-2009, 03:12 PM
  3. shooting a bullet
    By spot in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-15-2001, 10:40 AM
  4. Shooting
    By in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 01-15-2001, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean