Results 1 to 2 of 2

Thread: OpenGL openGlut marquee

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    1

    OpenGL openGlut marquee

    Hey everyone, first post, thanks in advance.

    I am brand new to openGL and I am trying to write a simple text marquee that displays text and moves it from the left to the right.

    I am having a terrificly terrible time trying to get this to work.

    Here is the code I am working with but I can't seem to get it to work the way I want it to, either it disappears in general, or it doesnt' reset, or it doesn't move properly. I think the basic idea is to create the text in the center of the screen and move the camera over it to simulate the text moving, but I can't seem to get it correct. If anyone could help I would greatly appreciate it.



    #include <math.h>
    #include <GL/glut.h>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>

    float ratio;
    float x=0.0f,y=0.0f,z=5.0f;
    float lx=.0001f,ly=0.0f,lz=0.0f;
    int font=(int)GLUT_BITMAP_8_BY_13;


    void changeSize(int w, int h)
    {

    // Prevent a divide by zero, when window is too short
    // (you cant make a window of zero width).
    if(h == 0)
    h = 1;

    ratio = 1.0f * w / h;
    // Reset the coordinate system before modifying
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Set the viewport to be the entire window
    glViewport(0, 0, w, h);

    // Set the clipping volume
    gluPerspective(45,ratio,0.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(x, y, z,
    0,0 ,0 ,
    0.0f,1.0f,0.0f);


    }



    void initScene() {

    // glEnable(GL_DEPTH_TEST);

    ratio = 1.0f * 640 / 360;
    // // Reset the coordinate system before modifying
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Set the viewport to be the entire window
    glViewport(0, 0, 640, 360);

    // Set the clipping volume
    gluPerspective(45,ratio,.1,1000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(x, y, z,
    0,0 ,0 ,
    0.0f,1.0f,0.0f);

    }




    void renderBitmapCharacher(float x, float y, float z, void *font,char *string)
    {

    char *c;
    glRasterPos2f(x, y);
    for (c=string; *c != '\0'; c++) {
    glutBitmapCharacter(font, *c);
    }
    }

    void renderScene(void) {



    x+=.00005f;
    if(x>=0.5f)
    x=0.0f;

    gluLookAt(x, y, z,
    x, y, z,
    0.0f,1.0f,0.0f);

    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    renderBitmapCharacher(0,0,0,(void *)font,"GLUT Tutorial");
    glPopMatrix();

    glFlush();
    glutSwapBuffers();
    }





    int main(int argc, char **argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(640,360);
    glutCreateWindow("SnowMen from Lighthouse 3D");

    initScene();

    glutDisplayFunc(renderScene);
    glutIdleFunc(renderScene);

    //glutReshapeFunc(changeSize);

    glutMainLoop();

    return(0);
    }

  2. #2
    Senior Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: OpenGL openGlut marquee

    Before gluLookAt, call glLoadIdentity(). Because each time you redraw, gluLookAt multiply is transform matrix with the matrix at the top of the stack, so object appear to drift away.

    Use a fixed camera and translate your string with the right parameter for the renderBitmapCharacter.

    With your code, I was able to translate the string along the x axis.

    Hope that help.

Similar Threads

  1. Regarding Importing files from Maya in to openglut
    By Mandeep85009 in forum OpenGL: Windows
    Replies: 0
    Last Post: 09-05-2012, 11:00 PM
  2. Drawing Selection Marquee With Perspective Camera
    By g8keepR in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-24-2009, 01:30 PM
  3. openglut for windows 98
    By Hurle in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-17-2002, 08:12 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