Results 1 to 8 of 8

Thread: Help needed regarding glortho

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    10

    Help needed regarding glortho

    hi

    I have just started learning opengl. I hope am explaining it rite.I am trying to draw a 2D square when a user clicks square button on the GUI. But when we draw objects we draw using opengl coordinates i guess between (1 and -1) by default. I have used gluortho function to change the coordinates to the window cordinates i.e gluortho2D(0,500,0,500).. but that doesnt works because i cant draw a ssquare with cmd like glvertex2f(50,50).

    I also want to move the square to certain location as i click and drag it.

    Hopefully someone could me some advice on this

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Help needed regarding glortho

    Could we see more code please? Projection setup, rendering code...

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    10

    Re: Help needed regarding glortho

    yeah sure

    //width =500, height =500
    void initScene()
    {
    ///All initialization stuff goes here
    glClearColor(1.0, 1.0, 1.0,1.0); //white background
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,WIN_WIDTH,0,WIN_HEIGHT,-1,1);
    glMatrixMode(GL_MODELVIEW);





    }

    int main(int argc, char **argv)
    {

    // setup glut
    glutInit(&argc, argv);
    initScene();
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE); //We'll discuss these later
    glutInitWindowPosition( 0, 0 );
    glutInitWindowSize( WIN_WIDTH , WIN_HEIGHT );
    // init();
    //You'll need a handle for your main window for GLUI
    main_window = glutCreateWindow( "Graph Maker" );
    glutDisplayFunc(Display );
    glutReshapeFunc( myGlutReshape );
    glutMotionFunc( myGlutMotion );
    glutMouseFunc( myGlutMouse );

    // Initialize my Scene


    //Build the GUI
    glui = GLUI_Master.create_glui( "Graph Maker GUI", 0, 600, 50 );
    GLUI_Panel *componentPanel = glui->add_panel("Graph Components");
    glui->add_button_to_panel(componentPanel, "Square", SQUARE_BUTTON_ID, buttonCB);
    glui->add_button_to_panel(componentPanel, "Triangle", TRIANGLE_BUTTON_ID, buttonCB);
    glui->add_separator();

    GLUI_Panel *colorPanel = glui->add_panel("Color");
    // These could be done with floats but I ran into some issues
    GLUI_Spinner *redValue = glui->add_spinner_to_panel(colorPanel, "Red", 2, &red, RED, colorCB);
    redValue->set_int_limits(0, 255);
    GLUI_Spinner *greenValue = glui->add_spinner_to_panel(colorPanel, "Green", 2, &green,GREEN, colorCB);
    greenValue->set_int_limits(0,255);
    GLUI_Spinner *blueValue = glui->add_spinner_to_panel(colorPanel, "Blue", 2, &blue, BLUE, colorCB);
    blueValue->set_int_limits(0.0, 255);
    glui->set_main_gfx_window( main_window );

    // We register the idle callback with GLUI, *not* with GLUT
    //GLUI_Master.set_glutIdleFunc( myGlutIdle );
    GLUI_Master.set_glutIdleFunc( NULL );
    glutMainLoop();
    return EXIT_SUCCESS;
    }

    drawing

    void drawSquare()
    {
    // Code to draw a square
    //if( flag==1)


    glColor3f(++red,green,blue);
    glBegin(GL_QUADS);
    glVertex2f(220,220);
    glVertex2f(220,250);
    glVertex2f(280,280);
    glVertex2f(220,280);

    glEnd();

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Help needed regarding glortho

    Code :
    glColor3f(++red,green,blue);

    Looks suspect. What does red, green and blue contain? "++red" looks weird since you are incrementing a float value and color values above 1.0 for every component will look like white (unless you are using a kind of tonemapping algorithm then).

    Do you refresh the screen somewhere? -> glutPostRedisplay()

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    10

    Re: Help needed regarding glortho

    yeah i refresh the screen..i am changing the color of the square i have set red to 0 initially...i am using the the variables later on to change the color of my squares as i click the respective button on GUI

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    10

    Re: Help needed regarding glortho

    void buttonCB(int control)
    {
    switch(control)
    {
    case SQUARE_BUTTON_ID:
    printf ("Square\n");
    myGlutDisplay( );
    break;
    case TRIANGLE_BUTTON_ID:
    printf("Triangle\n");
    break;
    }
    // This causes opengl to redraw
    glutPostRedisplay();

    }

  7. #7
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    10

    Re: Help needed regarding glortho

    Basically what i need is to drag the square as i click it. But when I click the square i get the world coordinates...so as i drag it i want to redraw it at every location...but i cant draw it as we draw using opengl coordinates or screen coordinates whatever it is called( sorry for the ignorance)...i want to draw the square corresponding to the mouse location in world coordinates...

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Help needed regarding glortho

    Sorry I though at the beginning that you did not see the square on the screen. To move the square relating to mouse position, you can use gluUnProject function.

Similar Threads

  1. glOrtho
    By Woods in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-24-2005, 08:39 AM
  2. Using glOrtho ()
    By rgreene in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-11-2002, 08:09 PM
  3. Help needed regarding GLOrtho
    By src in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2002, 01:36 AM
  4. glOrtho
    By sadhu in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-11-2002, 04:57 AM
  5. glOrtho
    By snowboy in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-30-2001, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean