I have knew that there is some problem in this code as if I run it nothing is drawn .
portion of program where wrong is located in this code
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
glPushMatrix();
glRotated((GLdouble) Vangle,1.0,0.0,0.0);
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glPopMatrix();
glutWireCube (1.0);
glFlush ();
}
can you tell what is wrong ?
I think in matrix stack methods (push and pop) , I do not know how do I use it
Note : value of Vangle is zero .
As pst pointed out: Move the glutWireCube() call inside the glPush/PopMatrix() pair.
Give this a shot:
#include <GL/glut.h>
void display()
{
glEnable( GL_DEPTH_TEST );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// projection
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double w = glutGet( GLUT_WINDOW_WIDTH );
double h = glutGet( GLUT_WINDOW_HEIGHT );
double ar = w / h;
gluPerspective( 60, ar, 0.1, 100 );
// "camera" transform
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// draw cube
glPushMatrix();
float Vangle = 0.0f;
glRotated((GLdouble) Vangle,1.0,0.0,0.0);
glutWireCube (1.0);
glPopMatrix();
glutSwapBuffers();
}
int main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
glutInitWindowSize( 640, 480 );
glutCreateWindow( "GLUT" );
glutDisplayFunc( display );
glutMainLoop();
return 0;
}
Related
I want to display random colors in the GL_POLYGON.
But the colors changes only on minimize and maximize.It picks a different color on maximization and a different color on minimization.But it randomizes the colors as long as i continue minimizing and maximizing
#include <GL/gl.h>
#include <GL/glut.h>
#include <cstdlib>
void display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
glBegin( GL_POLYGON );
for( int i = 0; i < 255; i++ )
{
glColor3ub( rand(), rand(), rand() );
}
glVertex3f( 0.25, 0.25, 0.0 );
glVertex3f( 0.75, 0.25, 0.0 );
glVertex3f( 0.75, 0.75, 0.0 );
glVertex3f( 0.25, 0.75, 0.0 );
glEnd();
glColor3f( 0.0, 0.0, 0.0 );
glRectf( 0.45, 0.25, 0.55, 0.05 );
glRectf( 0.35, 0.08, 0.65, 0.02 );
glFlush();
}
void init( void )
{
glClearColor( 1.0, 1.0, 1.0, 1.0 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 );
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( 250, 250 );
glutInitWindowPosition( 100, 100 );
glutCreateWindow( "Assignment" );
init();
glutDisplayFunc( display );
glutMainLoop();
return 0;
}
glutDisplayFunc() only calls your callback when the OS needs your window re-drawn. If you want more regular calls you need to trigger them yourself via glutPostRedisplay():
... When GLUT determines that the normal plane for the window needs to be redisplayed, the display callback for the window is called. ...
...
GLUT determines when the display callback should be triggered based on the window's redisplay state. The redisplay state for a window can be either set explicitly by calling glutPostRedisplay or implicitly as the result of window damage reported by the window system. Multiple posted redisplays for a window are coalesced by GLUT to minimize the number of display callbacks called.
I like to use glutTimerFunc() to call glutPostRedisplay() periodically:
#include <GL/glut.h>
#include <cstdlib>
void timer( int value )
{
glutPostRedisplay();
glutTimerFunc( 16, timer, 0 );
}
void display()
{
glClearColor( 0.2, 0.2, 0.2, 1 );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glBegin( GL_POLYGON );
glColor3ub( rand(), rand(), rand() );
glVertex3f( 0.25, 0.25, 0.0 );
glVertex3f( 0.75, 0.25, 0.0 );
glVertex3f( 0.75, 0.75, 0.0 );
glVertex3f( 0.25, 0.75, 0.0 );
glEnd();
glColor3f( 0.0, 0.0, 0.0 );
glRectf( 0.45, 0.25, 0.55, 0.05 );
glRectf( 0.35, 0.08, 0.65, 0.02 );
glutSwapBuffers();
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize( 250, 250 );
glutCreateWindow( "GLUT" );
glutDisplayFunc( display );
glutTimerFunc( 0, timer, 0 );
glutMainLoop();
return 0;
}
I am trying to draw some random points as the star in the window,
but points are not showing. But others objects are showing correctly.
My source code:
#include<windows.h>
#include <GL\glut.h>
#include <math.h> // For math routines (such as sqrt & trig).
GLfloat xRotated, yRotated, zRotated;
GLdouble radius=3;
GLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0}; //Black Color
GLfloat qaGreen[] = {0.0, 1.0, 0.0, 1.0}; //Green Color
GLfloat qaWhite[] = {1.0, 1.0, 1.0, 1.0}; //White Color
GLfloat qaRed[] = {1.0, 0.0, 0.0, 1.0}; //Red Color
// Set lighting intensity and color
GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};
GLfloat emitLight[] = {0.9, 0.9, 0.9, 0.9};
GLfloat Noemit[] = {0.0, 0.0, 0.0, 1.0};
// Light source position
GLfloat qaLightPosition[] = {1, 1, 1, 1};
void display(void);
void reshape(int x, int y);
void idleFunc(void)
{
if ( zRotated > 360.0 ) {
zRotated -= 360.0*floor(zRotated/360.0); // Don't allow overflow
}
if ( yRotated > 360.0 ) {
yRotated -= 360.0*floor(yRotated/360.0); // Don't allow overflow
}
zRotated += 0.05;
yRotated +=0.01;
display();
}
void initLighting()
{
// Enable lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);
}
void display(void){
glMatrixMode(GL_MODELVIEW);
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// clear the identity matrix.
glLoadIdentity();
glTranslatef(0.0,0.0,-40.0);
glPushMatrix();
glutSolidSphere(radius,25,25);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glRotatef(yRotated,0.0,2.0,0.0);
glTranslatef(5.0,0.0,0.0);
// Set the light position
glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emitLight); // Make sphere glow (emissive)
glutSolidSphere(radius/6,25,25);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Noemit);
glPopMatrix();
glTranslatef(0.0,0.0,0.0);
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glPointSize(3);
for(int i=1;i<100;i++){
int x = rand()%640 ;
int y = rand()%480;
glBegin(GL_POINTS);
glVertex2i (x,y);
glEnd();
}
glPopMatrix();
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glPointSize(3);
for(int i=1;i<100;i++){
int x = rand()%640 ;
int y = rand()%480;
glBegin(GL_POINTS);
glVertex2i (x,y);
glEnd();
}
glFlush(); //FOR RENDERING
glutSwapBuffers();
}
void reshape(int x, int y){
if(y == 0 || x == 0) return;
glMatrixMode(GL_PROJECTION);
gluPerspective(20.0,(GLdouble)x/(GLdouble)y,0.6,40.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); //Use the whole window for rendering
}
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(1000,600);
glutCreateWindow("Project_KD");
initLighting();
xRotated = yRotated = zRotated = 0.0;
glutIdleFunc(idleFunc);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Lots of wonkiness:
Couple instances of unmatched glPushMatrix()/glPopMatrix() calls; avoid over-/under-flowing the matrix stack; I like to use extra scopes to visually indicate matrix stack nesting.
Your point drawing was assuming an ortho projection while you only set a perspective one.
You left lighting enabled while trying to draw your points, resulting in very dark points everywhere except the bottom-left.
Your point drawing loop was duplicated for some reason; if you want double the stars adjust the for-loop end value instead of copy-pasting the loop.
You should use glutPostRedisplay() in your idle callback instead of calling display() directly.
Set your projection/modelview matrices each time through display() instead of setting them in a resize callback; helps reduce a source of mysterious matrix errors. The default resize callback calls glViewport() for you so you don't have to worry about doing that.
You're drawing the points ("stars"?) after the 3D spheres; I think the intent was to draw them before so they're "underneath".
Unholy mishmash of code formatting; recommend something like clang-format to keep that in check.
If you're using FreeGLUT on Windows (which you ought to be; it's really the only maintained GLUT implementation left) you don't need the #include <Windows.h>.
Recommend using a timer callback instead of an idle callback to update your simulation/animation. Without vsync that idle callback will be called incredibly often. With a timer callback you can simulate the even ~16 millisecond frames a vsync'd system will give you.
All together:
#include <GL/glut.h>
#include <cmath>
GLfloat xRotated, yRotated, zRotated;
GLdouble radius = 3;
void timer( int value )
{
if( zRotated > 360.0 )
{
zRotated -= 360.0 * floor( zRotated / 360.0 ); // Don't allow overflow
}
if( yRotated > 360.0 )
{
yRotated -= 360.0 * floor( yRotated / 360.0 ); // Don't allow overflow
}
zRotated += 5.0;
yRotated += 1.0;
glutTimerFunc( 16, timer, 0 );
glutPostRedisplay();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glDepthMask( GL_FALSE );
glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );
// 2D rendering
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 640, 0, 480, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPushMatrix();
{
glColor3f( 1.0, 1.0, 1.0 );
glPointSize( 3 );
glBegin( GL_POINTS );
for( int i = 1; i < 100; i++ )
{
int x = rand() % 640;
int y = rand() % 480;
glVertex2i( x, y );
}
glEnd();
}
glPopMatrix();
glDepthMask( GL_TRUE );
glEnable( GL_DEPTH_TEST );
// Enable lighting
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};
glLightfv( GL_LIGHT0, GL_SPECULAR, qaSpecularLight );
// 3D rendering
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double w = glutGet( GLUT_WINDOW_WIDTH );
double h = glutGet( GLUT_WINDOW_HEIGHT );
gluPerspective( 20.0, w / h, 0.1, 80.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -40.0 );
glPushMatrix();
{
glutSolidSphere( radius, 25, 25 );
}
glPopMatrix();
glPushMatrix();
{
glRotatef( yRotated, 0.0, 2.0, 0.0 );
glTranslatef( 5.0, 0.0, 0.0 );
GLfloat qaLightPosition[] = {1, 1, 1, 1};
glLightfv( GL_LIGHT0, GL_POSITION, qaLightPosition );
GLfloat emitLight[] = {0.9, 0.9, 0.9, 0.9};
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emitLight ); // Make sphere glow (emissive)
glutSolidSphere( radius / 6, 25, 25 );
GLfloat Noemit[] = {0.0, 0.0, 0.0, 1.0};
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, Noemit );
}
glPopMatrix();
glutSwapBuffers();
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( 1000, 600 );
glutCreateWindow( "Project_KD" );
xRotated = yRotated = zRotated = 0.0;
glutDisplayFunc( display );
glutTimerFunc( 0, timer, 0 );
glutMainLoop();
return 0;
}
I've written a simple opengl running in my ubuntu laptop. It is a small solar system including the sun and the earth, the earth rotates around the sun. The problem with my program is the screen keep blinking continuously every time I try to run it.
#include <GL/glut.h>
#define SUN_RADIUS 0.4
#define EARTH_RADIUS 0.06
#define MOON_RADIUS 0.016
GLfloat EARTH_ORBIT_RADIUS = 0.9;
GLfloat year = 0.0;
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void renderScene() {
gluLookAt(
0.0, 0.0, -4.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
);
glColor3f(1.0, 1.0, 0.7);
glutWireSphere(SUN_RADIUS, 50, 50);
glPushMatrix();
glRotatef(year, 0.0, 1.0, 0.0);
glTranslatef(EARTH_ORBIT_RADIUS, 0.0, 0.0);
glColor3f(0.0, 0.7, 1.0);
glutWireSphere(EARTH_RADIUS, 10, 10);
glPopMatrix();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
renderScene();
glFlush();
glutSwapBuffers();
}
void idle() {
year += 0.2;
display();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(600, 600);
glutCreateWindow("Solar System");
init();
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
}
gluLookAt() multiplies by the current matrix, it does not load a new one. Multiple gluLookAt()s multiplied together aren't very meaningful.
Reload proj/modelview matrices each frame, helps prevent matrix oddities.
Let GLUT do it's job, don't call display() from idle(), use glutPostRedisplay() instead. That way GLUT knows to call display() the next time through the event loop.
All together:
#include <GL/glut.h>
#define SUN_RADIUS 0.4
#define EARTH_RADIUS 0.06
#define MOON_RADIUS 0.016
GLfloat EARTH_ORBIT_RADIUS = 0.9;
GLfloat year = 0.0;
void renderScene()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( -1, 1, -1, 1, -100, 100 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt
(
0.0, 0.0, -4.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
);
glColor3f(1.0, 1.0, 0.7);
glutWireSphere(SUN_RADIUS, 50, 50);
glPushMatrix();
glRotatef(year, 0.0, 1.0, 0.0);
glTranslatef(EARTH_ORBIT_RADIUS, 0.0, 0.0);
glColor3f(0.0, 0.7, 1.0);
glutWireSphere(EARTH_RADIUS, 10, 10);
glPopMatrix();
}
void display()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(10.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderScene();
glutSwapBuffers();
}
void idle()
{
year += 0.2;
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(600, 600);
glutCreateWindow("Solar System");
glutDisplayFunc(display);
glutIdleFunc( idle );
glutMainLoop();
}
This may be due to tearing if you aren't doing any kind of v-sync (Which it doesn't look like your code is). Try adding a sleep time to your display method (like sleep(500)). This isn't the correct way to fix this, but this will allow you to verify that it is the issue. If it is, look into adding v-sync to your application.
#include <Windows.h>
#include <GL\glut.h>
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
bool init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glMatrixMode(GL_PROJECTION);
// Set grid to be from 0 to 1
gluOrtho2D(0.0, 3.0, 0.0, 3.0);
return true;
}
void drawline(float from_x, float from_y, float to_x, float to_y)
{
// From coordinate position
glVertex2f(from_x, from_y);
// To coordinate position
glVertex2f(to_x, to_y);
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0); // Color (RGB): Yellow
glLineWidth(2.0); // Set line width to 2.0
glLoadIdentity();
// Draw line
glBegin(GL_LINES);
drawline(0.25, 0.5, 0.4, 0.5);
drawline(0.4, 0.6, 0.4, 0.5);
drawline(0.4, 0.4, 0.4, 0.5);
drawline(0.6, 0.5, 0.75, 0.5);
glEnd();
// Draw triangle
glBegin(GL_TRIANGLES);
glVertex2f(0.4, 0.5);
glVertex2f(0.6, 0.6);
glVertex2f(0.6, 0.4);
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("My OpenGL program");
init();
// Draw shape one
glPushMatrix();
glTranslatef(1.5, 1.5, 0.0);
glutDisplayFunc(render);
glPopMatrix();
// Draw shape two
glPushMatrix();
glTranslatef(2.5, 2.5, 0.0);
glutDisplayFunc(render);
glPopMatrix();
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
I'm working to draw something like this: http://i.imgur.com/JJpbJ7M.png
I don't need the whole thing, I just want to be able to draw two shapes where I want them to be. However, this isn't working, can anyone point me into the right direction?
You almost had it.
Draw your shape(s) in render(), not main():
#include <GL/glut.h>
void drawline(float from_x, float from_y, float to_x, float to_y)
{
// From coordinate position
glVertex2f(from_x, from_y);
// To coordinate position
glVertex2f(to_x, to_y);
}
void drawShape()
{
glColor3f(1.0, 1.0, 0.0); // Color (RGB): Yellow
glLineWidth(2.0); // Set line width to 2.0
// Draw line
glBegin(GL_LINES);
drawline(0.25, 0.5, 0.4, 0.5);
drawline(0.4, 0.6, 0.4, 0.5);
drawline(0.4, 0.4, 0.4, 0.5);
drawline(0.6, 0.5, 0.75, 0.5);
glEnd();
// Draw triangle
glBegin(GL_TRIANGLES);
glVertex2f(0.4, 0.5);
glVertex2f(0.6, 0.6);
glVertex2f(0.6, 0.4);
glEnd();
}
void render(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( 0.0, 4.0, 0.0, 4.0, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Draw shape one
glPushMatrix();
glTranslatef(1.5, 1.5, 0.0);
drawShape();
glPopMatrix();
// Draw shape two
glPushMatrix();
glTranslatef(2.5, 2.5, 0.0);
drawShape();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("My OpenGL program");
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
I removed reshape() and init() since the default glutReshapeFunc() already calls glViewport() and you should be resetting your projection and modelview matrices each frame anyway.
I am trying to simply write anything on the screen. Drawing rectangles is easy enough. I am trying to place a text string sideways superimposed on a "book". It seems very simple and yet...
Just as a note, I tried to take advice from these forums so glDisable(GL_DEPTH_TEST); and glDisable(GL_LIGHTING); are probably not necessary. Additionally, is there a way to enable debugging myself? I am usually a fan of adding cout << "i reached this far yay" << endl; but it doesn't seem to like me when I place it in void Bookshelf()... it gives me a C2381 error ('function' : redefinition; __declspec(noreturn) differs)
main.cpp
#include "bookshelf.h"
void Initialize()
{
glClearColor (1.0, 1.0, 1.0, 0.0 );
glMatrixMode( GL_PROJECTION );
glOrtho(0,899,899,0,1,0);
}
void main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( 900, 900 );
glutInitWindowPosition( 510, 100 );
glutCreateWindow("Bookshelf - Ankit Ahuja");
Initialize();
glutDisplayFunc(Bookshelf);
glutMainLoop();
}
bookshelf.h
#include <GL/glut.h>
void Bookshelf()
{
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 0.0, 0.0, 0.0 );
glBegin( GL_QUADS );
//Code that draws a bookshelf
//Book1
glColor3f( 1.0, 0.25, 0.25 );
glVertex3i(240,70,0.5);
glVertex3i(260,70,0.5);
glVertex3i(260,180,0.5);
glVertex3i(240,180,0.5);
//BookTitle1
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glRotatef(90f,0.0f,0.0f,0.0f);
glColor3f( 0.0, 1.0, 0.0 );
glDisable(GL_LIGHTING);
glRasterPos3i(100,100,1);
char text[50]="Alphabet Soup is the best guys";
for(int i=0; i<50; i++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,(int)text[i]);
}
glPopMatrix();
//Book2
glColor3f( 0.8, 0.8, 0.0 );
glVertex2i(270,70);
glVertex2i(290,70);
glVertex2i(290,180);
glVertex2i(270,180);
//More books and shelves
glEnd();
glFlush();
}
You should set-up an orthographic projection by using the glOrtho before displaying your text.
Make sure you correctly push/pop the projection and modelview matrix before writing ur text so you are looking at something like:
glMatrixMode(GL_PROJECTION); //Select projection matrix
glPushMatrix(); //save it
glLoadIdentity();
glMatrixMode(GL_MODELVIEW); //Select modelview matrix
glPushMatrix(); //save it
glLoadIdentity();
// set up ur glOrtho
glOrtho(...);
glutBitmapCharacter(...)
glMatrixMode(GL_PROJECTION);
glPopMatrix(); //Restore your old projection matrix
glMatrixMode(GL_MODELVIEW);
glPopMatrix(); //Restore old modelview matrix