PDA

View Full Version : where can i find glRecti()



09-07-2000, 07:37 AM
can anyone help me to find the code for glRecti(GLint x1, GLint y2, GLint x2, GLint y2). i know this is the ready-made function, but i want to look the full code. thanks

Aster
09-07-2000, 10:27 AM
I'm not sure about the glRecti() command, but here is a function that i usually use to draw rectangles

GLvoid drawRectangle(GLfloat *v1, GLfloat *v2, GLfloat *v3, GLfloat *v4, GLfloat *col1, GLfloat *col2, GLfloat *col3, GLfloat *col4)
{
glBegin(GL_POYGON);
glColor4fv(col1);
glVertex4fv(v1);
glColor4fv(col2);
glVertex4fv(v2);
glColor4fv(col3);
glVertex4fv(v3);
glColor4fv(col4);
glVertex4fv(v4);
glEnd();
}

To see the effects of changing the color for each vertex, you have to call glShadeModel(GL_SMOOTH) amd glEnable(GL_BLEND).

Note, the function takes pointers (*v1 or *col1) to vertex and color arrays. That means you have to declare your vertices as 4-dimensional arrays:

GLfloat a1[]={50.0, 50.0, -50.0, 1.0};
GLfloat a2[]={50.0, 50.0, -50.0, 1.0};
GLfloat a3[]={50.0, 50.0, -50.0, 1.0};
GLfloat a4[]={50.0, 50.0, -50.0, 1.0};

and your colors as 4-dimensional arrays too:

GLfloat c1[]={1.0, 0.0, 0.0, 0.5};
GLfloat c2[]={0.0, 1.0, 0.0, 0.5};
GLfloat c3[]={0.0, 0.0, 1.0, 0.5};
GLfloat c4[]={1.0, 1.0, 0.0, 0.5};

Then you can pass them to the drawRectangle function.

I'm not sure if this answers your question, but try it anyway.

[This message has been edited by Aster (edited 09-07-2000).]

09-08-2000, 07:07 AM
uh... i'm not quite at that level yet, so i'm kind of confused reading your code. i'm only a beginer trying to draw a plain and simple rectangle. thanks anyway.

Aster
09-08-2000, 05:45 PM
To draw a rectangle, you can call this function

glRectd(x1, y1, x2, y2)

where x1, y1 are the coordinates of one vertex, and x2, y2 are the coordinates of the opposite vertex of the rectangle
In this case x1, y1, x2, and y2 must be of type GLdouble

if you want your coordinates to be a floating point single-precision numbers (type GLfloat), call

glRectf(x1, y1, x2, y2)

As you see, the letter after the glRect* indicates the type of parameters the function takes

You can also use

glRecti(x1, y1, x2, y2)

that takes integers, the function you uasked for

Here is the link where you can find lots of seful information as well as links to other pages about OpenGL: http://nehe.gamedev.net