0

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(); } 
5
  • Please properly format your code Commented Sep 25, 2012 at 22:04
  • What have you been able to draw to the screen? What exactly do you want drawn? If you provide some small thumbnails (even hand-drawn) of what is drawing and what isn't, it will better indicate the problems you are having. Commented Sep 25, 2012 at 22:56
  • I can draw all the rectangles without a problem, and have them filled in as intended, I just get stuck on the text part. Commented Sep 26, 2012 at 3:02
  • i47.tinypic.com/8zl95e.png is the portion of the project I can successfully create Commented Sep 26, 2012 at 4:12
  • update: text shows up but it is still not rotated properly Commented Sep 26, 2012 at 4:45

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

4 Comments

this worked. However, do you have any idea how I can now rotate the text string?
use the glRotatef around your view axis if u want in 2d
unfortunately, glRotatef in any form is not working. after doing more research, i'm not sure it's possible. is there an alternative to glutBitmapCharacter that will rotate?
ok i find out it is not possible; try to use free font instead. There is a tut on nehe about this nehe.gamedev.net/tutorial/2d_texture_font/18002 you might find some more recent tut on google about this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.