[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

OpenGL orthographic projection



Hi!

I'm trying to draw a mouse cursor using OpenGL, but I have come across a 
series of problems and don't find any reason for them. The code I use to draw 
the mouse cursor is pasted below. The problem I have is the orthographic 
projection: If I enable it, the mouse cursor will disappear without any 
reason apparent to me. The glOrtho() call should actually look like this:

  glOrtho(-1,1,1,-1,-1,1)

I have enlarged the region for testing purposes, but to no avail. Does any one 
of you OpenGL gurus see something strange in my code?

Gregor

  void Renderer::DrawMouseCursor()
  {
    float mouseCursorWidth, mouseCursorHeight;

    // We define a fixed mouse cursor size because it's size on screen 
shouldn't depend on screen resolution
    mouseCursorWidth=0.01;
    mouseCursorHeight=0.01;

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
    glBindTexture(GL_TEXTURE_2D,mouseCursor.GetTextureID());

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    glOrtho(-3,3,3,-3,-20,20);

    /*
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex2f(mouseCursorPosX+mouseCursorWidth,mouseCursorPosY+mouseCursorHeight);
    glTexCoord2f(0,1);
    glVertex2f(mouseCursorPosX-mouseCursorWidth,mouseCursorPosY+mouseCursorHeight);
    glTexCoord2f(1,1);
    glVertex2f(mouseCursorPosX-mouseCursorWidth,mouseCursorPosY-mouseCursorHeight);
    glTexCoord2f(1,0);
    glVertex2f(mouseCursorPosX+mouseCursorWidth,mouseCursorPosY-mouseCursorHeight);
    glEnd();
    */

    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex3f(mouseCursorPosX+mouseCursorWidth,mouseCursorPosY+mouseCursorHeight,-1.0);
    glTexCoord2f(0,1);
    glVertex3f(mouseCursorPosX-mouseCursorWidth,mouseCursorPosY+mouseCursorHeight,-1.0);
    glTexCoord2f(1,1);
    glVertex3f(mouseCursorPosX-mouseCursorWidth,mouseCursorPosY-mouseCursorHeight,-1.0);
    glTexCoord2f(1,0);
    glVertex3f(mouseCursorPosX+mouseCursorWidth,mouseCursorPosY-mouseCursorHeight,-1.0);
    glEnd();

    glPopMatrix();

    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
  }