Thread: Question on OpenGL

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732

    Question on OpenGL

    Hello guys,
    I just started learning opengl from past few days, so i dunno much about it. So probably some one out there would help me out in this simple problem which i am facing on co-ordinated, i mean setting the co-ordinates of the screen. Have a look at code below

    Code:
    #include<GL/gl.h>
    #include<GL/glu.h>
    #include<GL/glut.h>
    #include<windows.h>
    
    void Init(void);
    void Display(void);
    
    int main(int argc, char **argv)
    {
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(500,500);
        glutInitWindowPosition(100,100);
        glutCreateWindow("Polygon");
        Init();
        glutDisplayFunc(Display);
        glutMainLoop();
        
        return 0;
    }
    
    void Init(void)
    {
        glClearColor (0.0, 0.0, 0.0, 0.0);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluOrtho2D (0.0, 0.0, 0.0, 0.0);
    }
    
    void Display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0, 1.0, 1.0);
        
        glBegin(GL_POLYGON);
          glVertex2f(0.0, 0.0);
          glVertex2f(0.0, 1.0);
          glVertex2f(1.0, 2.0);
          glVertex2f(6.0, 1.0);
          glVertex2f(2.0, 0.0);
       glEnd();
       
       glFlush();
    }
    i wanted the co-ordinated 0.0 start from the top left of the screen. But by default it starts from the center of the screen which mean what ever i draw its all in the center but i wanted to be on top left of the screen. How do i do that, can any one please guide me in this.

    thank you

    ssharish2005

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Set gluOrtho2D to the proper dimensions.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by psychopath
    Set gluOrtho2D to the proper dimensions.
    thank u very much psychopath i changed it to

    Code:
    gluOrtho2D(0, 50, 50,   0);
    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Question
    By Halo3Master in forum Game Programming
    Replies: 16
    Last Post: 10-02-2007, 02:40 AM
  2. Opengl question
    By Shadowwoelf in forum Windows Programming
    Replies: 3
    Last Post: 06-03-2007, 01:21 PM
  3. OpenGL Camera Question
    By Astra in forum Game Programming
    Replies: 2
    Last Post: 03-25-2007, 01:53 PM
  4. OpenGL Question
    By Shamino in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2005, 02:35 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM