Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

OpenGl question

  • 18-03-2004 9:16pm
    #1
    Closed Accounts Posts: 1,135 ✭✭✭


    I have created an object and the camera pans around it... but I want to put text in the top left of the screen... I've done this .. but when I move the camera ... so does the text .. funny enough! :)

    Is there a way to brake up the environment or to fix the text so as it moves with the camera to appear still? I've been checking out the obvious sites but to of no avail.

    A link to a project something similar or suggestions would be much appriciated.


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    What you need to do is change to Orthographic projection mode (change to GL_PROJECTION matrix mode, reset the view matrix with glLoadIdentity() and then use gluOrtho2D() to set up the viewport) and translate to where you want to put the text using a glTranslatef()... simple as that!


  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    simple as that!
    I wish!

    Now my object flashes at me very briefly and then everything disapears. Thanks btw :D ... I seriously owe you a pint if I meet you in rl.

    I've never used gluOrtho2D() before... is there anything glaringly obvious about this:

    gluOrtho2D(30.0f, 30.0f, 30.0f, 30.0f);

    If I use any other values all I get is a blank ... no flash.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Not quite, the 4 parameters it takes are: gluOrtho2D(left, right, bottom, top). So if you want to set up a viewport that has values from 0,0 on the bottom left to 1,1 on the top right you would call gluOrtho2D(0,1,0,1). This way if you do a glTranslatef(.5,.5,0) you would translate to the center of the screen.

    gluOrtho2d is the same as calling glOrtho with a value of 1 for the near/far clipping planes. You're probably using gluPerspective or glFrustum already somewhere in your code to set up a perspective view (as opposed to a parallel view with glOrtho), they're kind of equivalent but for different types of projection.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Actually try using glRasterPos2f(x,y) to position on the screen instead, its probably easier and you dont have to muck around with projection matrices.


  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    hmm :dunno:

    when using glRasterPos2f() is moves unless at 0,0 ... but thats smack in the middle of the screen which is no good to me ... so I translate to (-10,5,1) but then it moves with the camera ... swapped the oder ... same thing happens.

    I then put gluOrtho2D(-20,1,1,20) ... *cause looking to translate to (-10,5,1)?*
    and it flashed at me... any other values like (0,1,01)... nothing happens.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    I'd say you're probably leaving out a glLoadIdentity() before putting the text onto the screen, otherwise of course it'll move with the view - thats the whole point of OpenGL being a state machine.

    You need to do a bit of reading I think.... have a look at a few of the links in the OpenGL FAQ, especially some of NeHe's earlier tutorials - they'll help you out alot with the basics of OpenGL. Use the MSDN Library to look up the various functions so you make sure you understand what they do, and if you haven't already read the first 3 chapters of the red book... do! (Especially the 3rd chapter since this is the part you don't seem to understand.) Then come back to us...


  • Registered Users, Registered Users 2 Posts: 95 ✭✭Mr.StRiPe


    Just use the following two functions as shown in void PrintToScreen()

    
    void ViewOrtho()	         // Sets up an Ortho View			
    {
                    glMatrixMode(GL_PROJECTION);				
    	glPushMatrix();								
    	glLoadIdentity();
    	glOrtho( 0, 640 , 0 , 480, -1, 1 ); 	
    	glMatrixMode(GL_MODELVIEW);				
    	glPushMatrix();							
    	glLoadIdentity();						
    }
    
    void ViewPerspective()      //Sets up a Perspective View			
    {
    	glMatrixMode(GL_PROJECTION);					
    	glPopMatrix();								
    	glMatrixMode(GL_MODELVIEW);		
    	glPopMatrix();							
    }
     
    void PrintToScreen()
    {
                  ViewOrtho();
                  
                  glPushMatrix(); 
                        glTranslatef(to position on screen you want);
                         // Run your print function here e.g glPrint("Hello World");
                  glPopMatrix();
    
                  ViewPerspective();
    }
    
    


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Ah cmon Ross I'm trying to get the guy to figure it out for himself! :p


  • Registered Users, Registered Users 2 Posts: 95 ✭✭Mr.StRiPe


    It would take a long time and a lot of frustration to figure that out from the red book! :)


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    heheh yeah maybe you're right. He should still read it though!


  • Advertisement
  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    Thanks Mr Stripe! :D Ross yer a darlin.

    Jazz man .. you're killin me here! you knew that all along?

    /me leaves in search of red book.


Advertisement