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

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

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();

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()

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

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

}

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…

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.