Fix drawing polygons. Fixes #35
This commit is contained in:
parent
d7342fa0c0
commit
df3cdf0ebb
31
GL/draw.c
31
GL/draw.c
|
@ -756,6 +756,8 @@ static void genArraysTriangleStrip(
|
||||||
output[count - 1].flags = PVR_CMD_VERTEX_EOL;
|
output[count - 1].flags = PVR_CMD_VERTEX_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_POLYGON_SIZE 10
|
||||||
|
|
||||||
static void genArraysTriangleFan(
|
static void genArraysTriangleFan(
|
||||||
ClipVertex* output,
|
ClipVertex* output,
|
||||||
GLsizei count,
|
GLsizei count,
|
||||||
|
@ -772,25 +774,23 @@ static void genArraysTriangleFan(
|
||||||
doTexture, doMultitexture, doLighting
|
doTexture, doMultitexture, doLighting
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert(count < MAX_POLYGON_SIZE);
|
||||||
|
static ClipVertex buffer[MAX_POLYGON_SIZE];
|
||||||
|
|
||||||
|
memcpy(buffer, output, sizeof(ClipVertex) * count);
|
||||||
|
|
||||||
|
// First 3 vertices are in the right place, just end early
|
||||||
swapVertex(&output[1], &output[2]);
|
swapVertex(&output[1], &output[2]);
|
||||||
output[2].flags = PVR_CMD_VERTEX_EOL;
|
output[2].flags = PVR_CMD_VERTEX_EOL;
|
||||||
|
|
||||||
GLsizei i = 3;
|
GLsizei i = 3, target = 3;
|
||||||
ClipVertex* first = &output[0];
|
ClipVertex* first = &output[0];
|
||||||
|
|
||||||
for(; i < count - 1; ++i) {
|
for(; i < count; ++i) {
|
||||||
ClipVertex* next = &output[i + 1];
|
output[target++] = *first;
|
||||||
ClipVertex* previous = &output[i - 1];
|
output[target++] = buffer[i];
|
||||||
ClipVertex* vertex = &output[i];
|
output[target] = buffer[i - 1];
|
||||||
|
output[target++].flags = PVR_CMD_VERTEX_EOL;
|
||||||
*next = *first;
|
|
||||||
|
|
||||||
swapVertex(next, vertex);
|
|
||||||
|
|
||||||
vertex = next + 1;
|
|
||||||
*vertex = *previous;
|
|
||||||
|
|
||||||
vertex->flags = PVR_CMD_VERTEX_EOL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,6 +838,7 @@ static void generate(ClipVertex* output, const GLenum mode, const GLsizei first,
|
||||||
doTexture, doMultitexture, doLighting
|
doTexture, doMultitexture, doLighting
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case GL_POLYGON:
|
||||||
case GL_TRIANGLE_FAN:
|
case GL_TRIANGLE_FAN:
|
||||||
genArraysTriangleFan(
|
genArraysTriangleFan(
|
||||||
output,
|
output,
|
||||||
|
@ -887,7 +888,7 @@ static void generate(ClipVertex* output, const GLenum mode, const GLsizei first,
|
||||||
nptr, nstride,
|
nptr, nstride,
|
||||||
doTexture, doMultitexture, doLighting
|
doTexture, doMultitexture, doLighting
|
||||||
);
|
);
|
||||||
} else if(mode == GL_TRIANGLE_FAN) {
|
} else if(mode == GL_TRIANGLE_FAN || mode == GL_POLYGON) {
|
||||||
genElementsTriangleFan(
|
genElementsTriangleFan(
|
||||||
output,
|
output,
|
||||||
count,
|
count,
|
||||||
|
|
|
@ -7,7 +7,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
|
||||||
{
|
{
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
||||||
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
|
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
|
||||||
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
|
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
|
||||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||||
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
||||||
|
|
||||||
|
@ -41,23 +41,36 @@ void DrawGLScene()
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
||||||
glLoadIdentity(); // Reset The View
|
glLoadIdentity(); // Reset The View
|
||||||
|
|
||||||
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
|
glTranslatef(-3.0f, 0.0f, -10.0f); // Move Left 1.5 Units And Into The Screen 6.0
|
||||||
|
|
||||||
// draw a triangle
|
// draw a triangle
|
||||||
glBegin(GL_POLYGON); // start drawing a polygon
|
glBegin(GL_TRIANGLES); // start drawing a polygon
|
||||||
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
|
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
|
||||||
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
|
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
|
||||||
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
|
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
|
||||||
glEnd(); // we're done with the polygon
|
glEnd(); // we're done with the polygon
|
||||||
|
|
||||||
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
|
glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
|
||||||
|
|
||||||
// draw a square (quadrilateral)
|
// draw a square (quadrilateral)
|
||||||
glBegin(GL_QUADS); // start drawing a polygon (4 sided)
|
glBegin(GL_QUADS); // start drawing a polygon (4 sided)
|
||||||
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
|
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
|
||||||
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
|
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
|
||||||
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
|
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
|
||||||
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
|
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
|
||||||
|
glEnd(); // done with the polygon
|
||||||
|
|
||||||
|
glTranslatef(3.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
glBegin(GL_POLYGON); // start drawing a polygon (4 sided)
|
||||||
|
glVertex3f(-0.0f, 1.0f, 0.0f); // Top Left
|
||||||
|
glVertex3f(-0.75f, 0.75f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, 0.0f, 0.0f); // Top Right
|
||||||
|
glVertex3f(-0.75f,-0.75f, 0.0f); // Bottom Right
|
||||||
|
glVertex3f(-0.0f,-1.0f, 0.0f); // Bottom Left
|
||||||
|
glVertex3f( 0.75f,-0.75f, 0.0f); // Bottom Right
|
||||||
|
glVertex3f( 1.0f, 0.0f, 0.0f); // Top Right
|
||||||
|
glVertex3f( 0.75f, 0.75f, 0.0f);
|
||||||
glEnd(); // done with the polygon
|
glEnd(); // done with the polygon
|
||||||
|
|
||||||
// swap buffers to display, since we're double buffered.
|
// swap buffers to display, since we're double buffered.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user