OpenGL glRectf() Not Working!!!

closed account (13bSLyTq)
Hi,

I am learning basics of OpenGL & I am attempting to use: glRectf() function to draw a basic Rectangle rather than use gl(GL_QUADS) and use 4 lines of code to draw a rectangle. But everytime I attempt to use glRectf() it never works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<Windows.h>
#include<GL\glut.h>
double yaxis;
double xaxis;

void Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glRotatef(yaxis, 0.0f, 1.0f, 0.0f);
	glRotatef(xaxis, 1.0f,  0.0f, 0.0f);

	glColor3f(1.0f,0.0f,0.0f); // Red color 
        glRectf(-0.75f,0.75f, 0.75f, -0.75f); //FAILING HERE!
	
	glFlush();
	glutSwapBuffers();
}
void KeyPresses(int key, int x, int y)
{
	if (key == GLUT_KEY_UP)
		xaxis += 15;
	if (key == GLUT_KEY_DOWN)
		xaxis -= 15;
	if (key == GLUT_KEY_RIGHT)
		yaxis += 15;
	if (key == GLUT_KEY_LEFT)
		yaxis -= 15;
	glutPostRedisplay();
}
void resizeing(int x, int y)
{
	glViewport(0, 0, (GLint)x, (GLint)y);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0f, (GLint)x, 0.0f, (GLint)y);
}
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE |GLUT_RGB);
	glutInitWindowSize(1000, 1000);
	glutCreateWindow("Give me GL! Good Luck");
	glEnable(GL_DEPTH_TEST);
	glutDisplayFunc(Display);
	glutSpecialFunc(KeyPresses);
	glutReshapeFunc(resizeing);
	glutMainLoop();
		return 0;
}


but for me nothing is showing, is there something wrong with my system or what does this work for you?

Or am I using the fuction wrong if so can you correct it.

Thanks in advance
closed account (N36fSL3A)
Can you see the rectangle if it's drawn with the usual way?
Last edited on
closed account (13bSLyTq)
Yep, but when glRectf() is called it fails to draw....
closed account (N36fSL3A)
(x)--------------------------
|                            |
|                            |
|                            |
|                            |
|                            |
---------------------------(x)
It works something like this... Maybe it's too small for you to notice...

(I actually never used this function before, and was unaware of it's existance... I'm basing my knowledge of it here:http://www.talisman.org/opengl-1.1/Reference/glRect.html )
Last edited on
closed account (13bSLyTq)
Okay, You are right, it was actually my graphics driver rather than the actual OpenGL. lol, Sorry for wasting time. Nevertheless got hand of basic concepts of OpenGL.
Topic archived. No new replies allowed.