Results 1 to 5 of 5

Thread: OpenGl background and part model proble

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

    OpenGl background and part model proble

    Hello,
    I have started a project and Im using openGl to render a 3D partview.
    Ive drawn a quad with the color gradient that I want to use as the background. And I used some existing code the draw a box with XYZ postion indicatiors.

    Here is the code:
    void CAvalonView:rawBackGround(void)
    {
    //glMatrixMode( GL_MODELVIEW );
    // glLoadIdentity();
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glBegin(GL_QUADS); // Start Drawing A Quad
    glColor4f(0.2f,0.2f,0.6f,1.0f);
    glVertex3f(-1.0f, 1.0f, -2.0f);// Top Left Of The Quad
    glVertex3f( 1.0f, 1.0f, -2.0f); // Top Right Of The Quad
    glColor4f(0.9f,0.9f,1.0f,1.0f);
    glVertex3f( 1.0f,-1.0f, -2.0f); // Bottom Right Of The Quad
    glVertex3f(-1.0f,-1.0f, -2.0f); // Bottom Left Of The Quad
    glEnd();

    }

    void CAvalonView:glDrawScene(void)
    {


    DrawBackGround();

    // Wireframe Mode


    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glBegin(GL_QUADS);
    glColor3f(0.f,0.f,1.f);
    // Front Side
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f( 1.0f, -1.0f, 1.0f);

    // Back Side
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f( 1.0f, 1.0f, -1.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);

    // Top Side
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f( 1.0f, 1.0f, -1.0f);
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);

    // Bottom Side
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);
    glVertex3f( 1.0f, -1.0f, 1.0f);
    glVertex3f(-1.0f, -1.0f, 1.0f);

    // Right Side
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f( 1.0f, -1.0f, 1.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);
    glVertex3f( 1.0f, 1.0f, -1.0f);

    // Left Side
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glEnd();

    // draw carthesian axes
    glBegin(GL_LINES);
    // red x axis
    glColor3f(1.f,0.f,0.f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(1.0f,0.0f,0.0f);
    glVertex3f(1.0f,0.0f,0.0f);
    glVertex3f(0.9f,0.1f,0.0f);
    glVertex3f(1.0f,0.0f,0.0f);
    glVertex3f(0.9f,-0.1f,0.0f);
    // green y axis
    glColor3f(0.f,1.f,0.f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,1.0f,0.0f);
    glVertex3f(0.0f,1.0f,0.0f);
    glVertex3f(0.1f,0.9f,0.0f);
    glVertex3f(0.0f,1.0f,0.0f);
    glVertex3f(-0.1f,0.9f,0.0f);
    // blue z axis
    glColor3f(0.f,0.f,1.f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,0.1f,0.9f);
    glVertex3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,-0.1f,0.9f);
    glEnd();

    What am I doing wrong?

    Thanks
    Derrek





    }

  2. #2
    Member Contributor
    Join Date
    Jul 2009
    Location
    Buenos Aires
    Posts
    67

    Re: OpenGl background and part model proble

    I need more information. What specific problem do you have?

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: OpenGl background and part model proble

    Thanks for the reply,
    In DrawBackground() if I enable GL(MODELVIEW) and Load Identity
    I get the background the way I like it but nothing from oglDrawScene()

    If I disable GL(MODELVIEW) and LoadIdentity I get oglDrawScene drawing correctly but the background quad is just a extra piece of the drawing and rotates and zooms along with the model.

    Basically I want DrawBackground to not move and stay in the back ground and the " model" the draw infront of the background.

    I hope that clearer

    Derrek

  4. #4
    Member Contributor
    Join Date
    Jul 2009
    Location
    Buenos Aires
    Posts
    67

    Re: OpenGl background and part model proble

    Well, you should set the modelview matrix to identity when drawing the background and to whatever transform you want for the cube. You can safely accomplish this by pushing and popping:


    glMatrixMode(GL_MODELVIEW); // maybe not needed
    glPushMatrix();
    glLoadIdentity();
    DrawBackGround();
    glPopMatrix();


    Also I would suggest to disable z writing and testing when drawing the background:

    glDepthMask(GL_FALSE);
    glDisable(GL_DEPTH_TEST);

    // Then as before
    glMatrixMode(GL_MODELVIEW); // maybe not needed
    glPushMatrix();
    glLoadIdentity();
    DrawBackGround();
    glPopMatrix();

    // And reenable those
    glDepthMask(GL_TRUE);
    glEnable(GL_DEPTH_TEST);

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: OpenGl background and part model proble

    Thanks so much

    that fixed it!!!!!

    Thanks again
    Derrek

Similar Threads

  1. Moving part of model on circle
    By Hitokage in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-13-2012, 11:50 AM
  2. Replies: 6
    Last Post: 04-26-2005, 04:57 PM
  3. Another proble with object's id
    By jirkamelich in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-09-2002, 12:38 PM
  4. Custom projection matrix: part ortho, part frustum
    By joelsk in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-30-2000, 07:01 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