Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Display over background

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    9

    Display over background

    I was able to display a .bmp file for a background on a window....After reading the code(provided by another person) it looks like it maps the .bmp from window edge to window edge. Problem is that now I can't display new objects in front of this background...


    Basically one function draws the map in function drawglscene. If I write code after the funciton drawmap, nothing shows no matter where in the z-axis I place the object. But if I comment out my drawmap funciton the other objects display.


    Any suggestions??

  2. #2
    Member Newbie
    Join Date
    May 2001
    Posts
    39

    Re: Display over background

    What z value you use for drawing the background?

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    9

    Re: Display over background

    This is the code...see how it maps the texture to the screen size......

    I'm gonna look into the ortho2d() and normal() to see if they have a z-axis to put the .bmp file at as soon as I get outa work;

    AS for the objects, I tried +/- z-axis locations and still they did not display unless I commented out drawmap();


    void DrawMap()
    {
    // Window size (GLdouble)
    int w = 800;
    int h = 600;

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, w, 0, h);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);

    glDisable(GL_DITHER);
    glShadeModel(GL_FLAT);

    glEnable(GL_TEXTURE_2D);

    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

    glBegin(GL_QUADS);
    GLfloat fw = (GLfloat) w;
    GLfloat fh = (GLfloat) h;
    glNormal3f( 0.0f, 0.0f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( fw, fh, 0.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0, fh, 0.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( fw, 0, 0.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glPopAttrib();
    }

  4. #4
    Member Newbie
    Join Date
    May 2001
    Posts
    39

    Re: Display over background

    Ok, I don't see nothing wrong in you code, but one consideration.

    gluOrtho2D create a visualization box between -1 and 1 in the z axis. then any vertex drawing with z < -1 or z > 1 is not displayed (is clip).

    You use depth test?
    You say that if you comment DrawMap works, but what Projection Matrix you use then?


    [This message has been edited by Boresight (edited 05-23-2001).]

  5. #5
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    9

    Re: Display over background

    Basically I tested using a simple triangle. I translated this at varying z-depths.

    This is what I have in drawglscene(Very Basics):
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
    glLoadIdentity(); // Reset The Current Modelview Matrix


    DrawMap();

    glTranslatef(0.0,0.0,-4.0);


    //Test object is triangle
    //at later date, change to rectangles.
    //map ship textures to the rectangles.
    glBegin(GL_TRIANGLES); // Drawing Using Triangles
    glVertex3f( 0.0f, 1.0f, 0.0f); // Top
    glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
    glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
    glEnd();

    You mentioned "gluOrtho2D create a visualization box between -1 and 1 in the z axis. then any vertex drawing with z < -1 or z > 1 is not displayed (is clip)"

    How would I expand this "box", for example, 6 and -6 in the z-axis.

    Or does ortho2d automatically display in 1 to -1 z-axis? If so what would be a solution to expand this viewing area.

    My goal:

    Display background map.

    Dsplay objects(containing ship .bmp's) in front of the background.

    Move the objects with each mouse click.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    319

    Re: Display over background

    Try disabling Z buffering before calling DrawMap.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Display over background

    You can use glOrtho(left, right, bottom, top, zNear, zFar) instead of gluOrtho2D().

    Also, try this code instead:
    Code :
    drawOneTriangle();
    glTranslatef(0.0f, 0.0f, -4.0f);
    DrawMap();
    I think (not at home so I can't test it) that the way you do it, you draw the map, then draw a triangle translated down the negative z axis i.e. [i]into the screen, behind the map[\i]. You could either try my code, or try changing the glTranslatef that you've got to a positive value. I'd also throw in a call to glTranslatef(0.0f, 0.0f, some_negative_z_value) after your // reset the current modelview matrix line to move the "camera" away from your objects.

    Hope that helps.

  8. #8
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    9

    Re: Display over background

    I've been thumbing through my opengl book and I'm getting bummed now.

    I changed from the ortho2d to glortho. I implemented it as glOrtho(0,w,0,h, 0, -10); //(left,right,bottom,top,near,far)


    I was hoping to display objects between -1 to -6 in the z-axis. I noticed that when altering the triangle's vertices that it does display on the sceen.

    The catch is that it seems to take on the color of the .bmp file so I can never distinguish if it is displayed on the screen. Tested this by moving the vertices of the background quad to -6 in the z-axis. The trianlge appears, but the color is green like the map.

    The code does disable the texture after the image is mapped to a quad in my DrawMap() function so this should not be happening.

    I've included a link to the source code with the small image below.


    So if someone wouldnt mind pointing out what I'm doing wrong, it would be very appreciated.

    http://members.nbci.com/drumdummy/MapTest.zip

  9. #9
    Member Contributor
    Join Date
    Mar 2001
    Posts
    64

    Re: Display over background

    There is a problem in the code you posted.

    Code :
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, w, 0, h);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    Note that the Projection Matrix is pushed followed by the Modelview Matrix. Then later, you Pop them off as follows-

    Code :
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    This would pop the Modelview Matrix into the Projection matrix and the Projection into the Modelview.

    You may also wish to do a-

    glDepthMask(glFalse);

    before drawing your background so that it doesn't write its value into the Z-Buffer.

  10. #10
    Senior Member Regular Contributor
    Join Date
    May 2001
    Location
    Germany, Hannover
    Posts
    160

    Re: Display over background

    try:
    glDisable(GL_DEPTH_TEST);
    //draw here your background-image
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    //draw other stuff ...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 04-24-2014, 12:36 PM
  2. Replies: 4
    Last Post: 05-23-2012, 10:24 AM
  3. is it possible to display a background image ?
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-21-2004, 04:56 PM
  4. Remote display NT->Irix for stereo display
    By YvesRubin in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-09-2002, 02:29 AM
  5. Display list to display models...Should I use them?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-27-2000, 12:49 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