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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#define DEFAULT_WIDTH 600
#define DEFAULT_LENGTH 200
#define DEFAULT_BORDER 50
void draw(GLObj * Obj)
{
int i;
if(Obj->Mode & GLMODE_POINTS)
{
for(i=0; i<Obj->GLPointsPointListSize; i++)
{
glBegin(GL_POINTS);
glColor3f(((Obj->GLPointsPointList[i].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLPointsPointList[i].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLPointsPointList[i].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLPointsPointList[i].x,
Obj->GLPointsPointList[i].y,
Obj->GLPointsPointList[i].z);
glEnd();
}
}
if(Obj->Mode & GLMODE_LINES)
{
for(i=0; i<Obj->GLLinesPointListSize; i+=2)
{
glBegin(GL_LINES);
glColor3f(((Obj->GLLinesPointList[i].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLLinesPointList[i].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLLinesPointList[i].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLLinesPointList[i].x,
Obj->GLLinesPointList[i].y,
Obj->GLLinesPointList[i].z);
glColor3f(((Obj->GLLinesPointList[i+1].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLLinesPointList[i+1].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLLinesPointList[i+1].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLLinesPointList[i+1].x,
Obj->GLLinesPointList[i+1].y,
Obj->GLLinesPointList[i+1].z);
glEnd();
}
}
if(Obj->Mode & GLMODE_TRIANGLES)
{
for(i=0; i<Obj->GLTrianglesPointListSize; i+=3)
{
glBegin(GL_TRIANGLES);
glColor3f(((Obj->GLTrianglesPointList[i].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLTrianglesPointList[i].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLTrianglesPointList[i].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLTrianglesPointList[i].x,
Obj->GLTrianglesPointList[i].y,
Obj->GLTrianglesPointList[i].z);
glColor3f(((Obj->GLTrianglesPointList[i+1].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLTrianglesPointList[i+1].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLTrianglesPointList[i+1].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLTrianglesPointList[i+1].x,
Obj->GLTrianglesPointList[i+1].y,
Obj->GLTrianglesPointList[i+1].z);
glColor3f(((Obj->GLTrianglesPointList[i+2].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLTrianglesPointList[i+2].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLTrianglesPointList[i+2].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLTrianglesPointList[i+2].x,
Obj->GLTrianglesPointList[i+2].y,
Obj->GLTrianglesPointList[i+2].z);
glEnd();
}
}
if(Obj->Mode & GLMODE_QUADS)
{
for(i=0; i<Obj->GLQuadsPointListSize; i+=4)
{
glBegin(GL_QUADS);
glColor3f(((Obj->GLQuadsPointList[i].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLQuadsPointList[i].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLQuadsPointList[i].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLQuadsPointList[i].x,
Obj->GLQuadsPointList[i].y,
Obj->GLQuadsPointList[i].z);
glColor3f(((Obj->GLQuadsPointList[i+1].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLQuadsPointList[i+1].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLQuadsPointList[i+1].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLQuadsPointList[i+1].x,
Obj->GLQuadsPointList[i+1].y,
Obj->GLQuadsPointList[i+1].z);
glColor3f(((Obj->GLQuadsPointList[i+2].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLQuadsPointList[i+2].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLQuadsPointList[i+2].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLQuadsPointList[i+2].x,
Obj->GLQuadsPointList[i+2].y,
Obj->GLQuadsPointList[i+2].z);
glColor3f(((Obj->GLQuadsPointList[i+3].xColor & 0x00FF0000) >> 16) / 255.0,
((Obj->GLQuadsPointList[i+3].yColor & 0x0000FF00) >> 8) / 255.0,
((Obj->GLQuadsPointList[i+3].zColor & 0x000000FF)) / 255.0);
glVertex3f(Obj->GLQuadsPointList[i+3].x,
Obj->GLQuadsPointList[i+3].y,
Obj->GLQuadsPointList[i+3].z);
glEnd();
}
}
if(Obj->Mode & GLMODE_POLYGON)
{
for(i=0; i<Obj->GLLinesPointListSize; i++)
{
glBegin(GL_POLYGON);
glEnd();
}
}
}
void reshape(int width, int height)
{
if (height==0) // Prevent A Divide By Zero By
height=1; // Making Height Equal One
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(-DEFAULT_BORDER,DEFAULT_WIDTH+DEFAULT_BORDER,-DEFAULT_BORDER,DEFAULT_LENGTH+DEFAULT_BORDER,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
draw(&Obj3d);
glFlush() ;
glutSwapBuffers();
} |
Partager