Results 1 to 2 of 2

Thread: Material Issue

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Material Issue

    Hi, Im making a 3D game for an assignment but am having an issue with my cube that I read in from a file + my DisplayHUD. Basically instead of using the colours from the file/HUD they are taking on the material that I used for a previous object. If anyone could shed some light onto why this is happening I would apreciate it, thanks.

    void displayHUD(){
    char message[39];
    char win[6];
    sprintf(message, "W-Up S-Down A-Left D-Right R-Reset");

    glColor3f(1.0, 1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, 100, 0, 100);
    outputText(5, 95, message);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    }
    void display() {
    char message[30];
    glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z, cam.lookAt.x,
    cam.lookAt.y, cam.lookAt.z,
    cam.up.x, cam.up.y, cam.up.z);
    glPushMatrix();
    glTranslated(0, 4, 0);
    glScalef(8, 1, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(0, -3, 0);
    glScalef(8, 1, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(-3.5, 0.5, 0);
    glScalef(1, 6, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(3.5, 0.5, 0);
    glScalef(1, 6, 1);
    glRotated(90, 0, 0 , 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(1.5, 0, 0);
    glScalef(1, 1, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(1.5, -2, 0);
    glScalef(1, 1, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(-2.5, -1, 0);
    glScalef(1, 1, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(1.5, 2.5, 0);
    glScalef(1, 2, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();
    glPushMatrix();
    glTranslated(-0.5, 1, 0);
    glScalef(1, 3, 1);
    setMaterial(&wallbox);
    glutSolidCube(1.0);
    glPopMatrix();

    glPushMatrix();
    glutKeyboardFunc(PlayerkeyPressed);
    glTranslated(playerLocX, playerLocY, 0);
    glScalef(1, 1, 1);
    setMaterial(&playerbox);
    glutSolidCube(1.0);
    glPopMatrix();

    glPushMatrix();
    glTranslated(-2.5, 3, 0);
    glScalef(0.999, 0.999, 0.999);
    setMaterial(&finishbox);
    glutSolidCube(1.0);
    glPopMatrix();

    glPushMatrix();
    glTranslated(boxLocX, boxLocY, 0);
    glScalef(1, 1, 1);
    cube();
    glPopMatrix();

    displayHUD();
    glFlush();
    }

    void init() {
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glEnable(GL_/LIGHTING);
    glEnable(GL_LIGHT0);
    setLight(&whiteLighting);
    wallBoundingBoxes();
    read_file("cube.txt");

    }

    int main(int argc, char** argv) {
    glutInitDisplayMode(GLUT_RGB |GLUT_DEPTH);
    glutInit(&argc, argv);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Qubz");
    glEnable(GL_DEPTH_TEST);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    init();
    glutMainLoop();
    }
    The bits in bold are taking on the material from the bit in red.

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Re: Material Issue

    This isn't my whole code, just the bits I thought matterd. If you need to see more let me know.

Similar Threads

  1. Material Problem
    By Kieran in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-22-2012, 08:43 AM
  2. material qualities
    By zed in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-22-2004, 02:54 PM
  3. Computer speed - issue or non-issue
    By howie in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-11-2004, 05:21 AM
  4. Material
    By mphanke in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-10-2002, 02:15 PM
  5. Material
    By Claudio in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 07-09-2000, 10:50 PM

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