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);
}