Merge branch '35-fix-polygons' into 'master'

Fix drawing polygons. Fixes #35

Closes #35

See merge request simulant/GLdc!33
This commit is contained in:
Luke Benstead 2019-03-07 21:45:46 +00:00
commit dc6b067e58
2 changed files with 40 additions and 26 deletions

View File

@ -756,6 +756,8 @@ static void genArraysTriangleStrip(
output[count - 1].flags = PVR_CMD_VERTEX_EOL;
}
#define MAX_POLYGON_SIZE 10
static void genArraysTriangleFan(
ClipVertex* output,
GLsizei count,
@ -772,25 +774,23 @@ static void genArraysTriangleFan(
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]);
output[2].flags = PVR_CMD_VERTEX_EOL;
GLsizei i = 3;
GLsizei i = 3, target = 3;
ClipVertex* first = &output[0];
for(; i < count - 1; ++i) {
ClipVertex* next = &output[i + 1];
ClipVertex* previous = &output[i - 1];
ClipVertex* vertex = &output[i];
*next = *first;
swapVertex(next, vertex);
vertex = next + 1;
*vertex = *previous;
vertex->flags = PVR_CMD_VERTEX_EOL;
for(; i < count; ++i) {
output[target++] = *first;
output[target++] = buffer[i];
output[target] = buffer[i - 1];
output[target++].flags = PVR_CMD_VERTEX_EOL;
}
}
@ -838,6 +838,7 @@ static void generate(ClipVertex* output, const GLenum mode, const GLsizei first,
doTexture, doMultitexture, doLighting
);
break;
case GL_POLYGON:
case GL_TRIANGLE_FAN:
genArraysTriangleFan(
output,
@ -887,7 +888,7 @@ static void generate(ClipVertex* output, const GLenum mode, const GLsizei first,
nptr, nstride,
doTexture, doMultitexture, doLighting
);
} else if(mode == GL_TRIANGLE_FAN) {
} else if(mode == GL_TRIANGLE_FAN || mode == GL_POLYGON) {
genElementsTriangleFan(
output,
count,

View File

@ -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
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
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
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
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
glBegin(GL_TRIANGLES); // 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
glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
// draw a square (quadrilateral)
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 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); // 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.