Advertisement

2D drawing

Started by January 27, 2002 10:43 AM
9 comments, last by L4k4I 23 years ago
how can i draw something on the screen in 2D without sin and cos? e.g. i want to draw a health counter in the upper right corner of the screen. or i want to draw 2d text on the screen. how can i do it? is there a gl syntax? thanx to everyone who gives me an answer and sorry for my bad english. L4k4I
No problem. Do two things before drawing 2d stuff:

1)Reset your matrices.
2)Disable depth testing. glDisable(GL_DEPTH_TEST)

Then draw things with X,Y coordinates (Z-coords set to zero). The upper-right corner of the screen is (1,1) and the lower-left is (-1,-1) with the center being zero.
Advertisement
Thank you but(stupid question) how do i reset my matrices?
reset matrices = glLoadIdentity()
Another thing, if you draw something with Z = 0, it wont show. Draw with z = near clip plane, which you defined in your gluPerspective() or glFrustrum() call. Also, the corners of the screen will only correspond to what feagle814 said with few specific values for fov and near clip plane.

For 2d drawing, look into glOrtho(). Much better, and x and y coordinates correspond to pixel values on the screen, which may or may not be what you want.
Thank you for your answers but it still doesn''t work.
maybe im just too stupid.
here is my code . i hope someone can help me with this piece of shit.

****************************************************************

glpolygonmode(GL_FRONT,GL_FILL);
glloadidentity;
gldisable(GL_DEPTH_TEST);
gldisable(GL_CULL_FACE);
gltranslatef(1,1,0.1);
glenable(GL_BLEND);
glbindtexture(GL_TEXTURE_2D,texture[2]);
glbegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2d(0,0);

glTexCoord2f(1,0);
glVertex2d(0.01,0);

glTexCoord2f(1,1);
glVertex2d(0.01,0.01);

glTexCoord2f(0,1);
glVertex2d(0,0.01);
glend;
glenable(GL_CULL_FACE);
gldisable(GL_BLEND);
glenable(GL_DEPTH_TEST);
glpolygonmode(GL_FRONT,GL_FILL);

****************************************************************

its just a newbe code but i don''t know what im doing wrong.

thanx 2 everyone who can help me.
Advertisement
please, what do you mean by "it still doesn''t work" ?
what''s the problem ?

can''t you see the polygons ?
do they appear in a strange colour ?
are they scaled, aren''t they on right location ?

I''m sorry, but I don''t think we can''t help a lot if we just know "it still doesn"t work" :p
so try this :

glPolygonMode(GL_FRONT,GL_FILL);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glTranslatef(0,0,-0.1);
glEnable(GL_BLEND);
glBindtexture(GL_TEXTURE_2D,texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2d(0,0);
glTexCoord2f(1,0); glVertex2d(0.01,0);
glTexCoord2f(1,1); glVertex2d(0.01,0.01);
glTexCoord2f(0,1); glVertex2d(0,0.01);
glEnd;
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT,GL_FILL);

with
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

It should work
THANX A LOT IT WORKS . I CAN''t SAY HOW HAPPY I AM . I TRIED IT SO LONG!!
but i still don''t know what ive done wrong.
I change
gltranslatef(1,1,0.1); -> glTranslatef(0,0,-0.1);

You move 0.1 along the Z axis, so when you draw quad you can not see it, because the quad is behind you. But when you move
-0.1 along the Z axis, you can see it - it is in front of you

This topic is closed to new replies.

Advertisement