How can I set drawing coordinate from left bottom corner?

#include <windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>

#define WIDTH 600
#define HEIGHT 400

void reshape(int width, int height)
{
	glViewport(0,0,600,400);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-WIDTH/2, WIDTH/2, -HEIGHT/2, HEIGHT/2, -1000, 1000);
}

static void display(void) {	
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POLYGON);
		glColor3f(1, 0, 0);
		glVertex3f(0, 0, 0);
		glColor3f(0, 1.0, 0);
		glVertex3f(0.5, 0, 0);
		glColor3f(0, 0, 1);
		glVertex3f(0.25,0.5,0);
	glEnd();
    glutSwapBuffers();	
}

int main(int argc, char *argv[]) {
    glutInit(&argc, argv);
    glutInitWindowSize(600,400);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Graphics Lab");
	glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

This has a output with black window. What should I do?

&colagl
I’m somewhat “old gl”-stupid, but aren’t vertex-units pixels? … Maybe you just need a pair of glasses.

I could not understand what you said. Sorry. Will you explain about the mistake?

you have a 400x600 pixel-sized window and a less than 1x1 pixel-sized triangle.

This does not relate to your initial question. To that: the coordinates you set will be interpretated by opengl as rooted in lower-left corner … that’s a problem if you have coordinate-generating algorifhms rooted in upper-left. In your present situation you just have to /think/ a bit different.

I think, width=600 and height=400. Will you paste or write the correct code so that left,bottom is 0,0 and there is a triangle or polygon there?

My consern is, that the triangle is too small to be seen on the screen. Try to factor up the vertex-positions by 10 and test the changes.

This still draws triangle at center of black screen. What should I do to draw it at left,bottom?

so, the triangle is drawn afterall … not just a black screen. You havn’t made yourself clear.

set the viewport … look up it’s parameters

Will you explain the glortho function? glOrtho(-WIDTH/2, WIDTH/2, -HEIGHT/2, HEIGHT/2, -1000, 1000);

glOrtho constructs a transformation which maps the specified coordinates to the signed unit square: [-1,1]×[-1,1]. If left=-right and bottom=-top, then the origin (0,0) is in the centre of the viewport. If you want the origin at the lower-left corner, use

glOrtho(0, WIDTH, 0, HEIGHT, -1000, 1000);

glOrtho(0, WIDTH, 0, HEIGHT, -1000, 1000); What do -1000 and 1000 do here?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.