Fix issues with triangle fans / polygons

This commit is contained in:
Luke Benstead 2019-03-10 12:24:27 +00:00
parent 1807a0119c
commit b00b65af54
2 changed files with 40 additions and 4 deletions

View File

@ -768,19 +768,24 @@ static void genArraysTriangleFan(
const GLubyte* nptr, GLuint nstride,
GLboolean doTexture, GLboolean doMultitexture, GLboolean doLighting) {
assert(count < MAX_POLYGON_SIZE);
static ClipVertex buffer[MAX_POLYGON_SIZE];
genArraysCommon(
output, count,
vptr, vstride, cptr, cstride, uvptr, uvstride, stptr, ststride, nptr, nstride,
doTexture, doMultitexture, doLighting
);
assert(count < MAX_POLYGON_SIZE);
static ClipVertex buffer[MAX_POLYGON_SIZE];
if(count <= 3){
swapVertex(&output[1], &output[2]);
output[2].flags = PVR_CMD_VERTEX_EOL;
return;
}
memcpy(buffer, output, sizeof(ClipVertex) * count);
// First 3 vertices are in the right place, just end early
swapVertex(&output[1], &output[2]);
output[2].flags = PVR_CMD_VERTEX_EOL;
GLsizei i = 3, target = 3;

View File

@ -41,7 +41,7 @@ void DrawGLScene()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(-3.0f, 0.0f, -10.0f); // Move Left 1.5 Units And Into The Screen 6.0
glTranslatef(-3.0f, 1.5f, -10.0f); // Move Left 1.5 Units And Into The Screen 6.0
// draw a triangle
glBegin(GL_TRIANGLES); // start drawing a polygon
@ -73,6 +73,37 @@ void DrawGLScene()
glVertex3f( 0.75f, 0.75f, 0.0f);
glEnd(); // done with the polygon
glTranslatef(-6.0f, -3.0f, 0.0f);
// draw a triangle
glBegin(GL_POLYGON); // start drawing a polygon
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 Left
glEnd(); // we're done with the polygon
glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
// draw a square (quadrilateral)
glBegin(GL_POLYGON); // start drawing a polygon (4 sided)
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); // Bottom Right
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
// swap buffers to display, since we're double buffered.
glKosSwapBuffers();
}