Primitives Declaration for my functions

int round(float x){
return ((int)(x + 0.5));
}

//—————————————————————————–
// Name:
// Desc:
//—————————————————————————–
Color setColor(float red, float green, float blue){
Color col;
col.red = red; col.green = green; col.blue=blue;

return col;
}

//—————————————————————————–
// Name:
// Desc:
//—————————————————————————–
Point setPoint(int x, int y){
Point p;
p.x = x; p.y = y;

return p;
}

//—————————————————————————–
// Name: setPixel
// Desc:
//—————————————————————————–
void setPixel(int x, int y, Color c){
glPushAttrib(GL_ALL_ATTRIB_BITS);
glColor3f(c.red, c.green, c.blue);

glBegin(GL_POINTS);
glVertex3f(x,y,0);
glEnd();
glPopAttrib();
}

//—————————————————————————–
// Name:
// Desc:
//—————————————————————————–
Color getPixel(int x, int y){ // gets the color of the pixel at (x,y)
Color c;
float color[4];

glReadPixels(x,y,1,1,GL_RGBA, GL_FLOAT, color);
c.red = color[0]; c.green = color[1]; c.blue = color[2];

return c;
}

//—————————————————————————–
// Name: outputText()
// Desc: x,y, the string
// Source: http://www.lighthouse3d.com/opengl/glut/
//—————————————————————————–
void outputText(float x, float y, char *string){
char *c;

glRasterPos3f(x,-y,0);

for (c=string; *c != ”; c++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c);

}

//—————————————————————————–
// Name: floatToStr()
// Desc: accepts a floating point number and returns a string
//—————————————————————————–
char * floatToStr(float x){
char *str = new char[7];
sprintf(str, “%4.2f”, x);
return str;
}

Leave a Reply