Fix bug when clipping triangle strips
This commit is contained in:
parent
81b52e7a18
commit
cdef5972f5
15
GL/clip.c
15
GL/clip.c
|
@ -228,7 +228,6 @@ void clipTriangleStrip(AlignedVector* vertices, AlignedVector* outBuffer) {
|
|||
|
||||
ClipVertex output[4];
|
||||
|
||||
/* FIXME: Interpolate other values (colors etc.) */
|
||||
clipLineToNearZ(v2->xyz, v3->xyz, CLIP_DISTANCE, output[2].xyz, &t1);
|
||||
clipLineToNearZ(v1->xyz, v3->xyz, CLIP_DISTANCE, output[3].xyz, &t2);
|
||||
|
||||
|
@ -261,7 +260,6 @@ void clipTriangleStrip(AlignedVector* vertices, AlignedVector* outBuffer) {
|
|||
|
||||
ClipVertex output[4];
|
||||
|
||||
/* FIXME: Interpolate other values (colors etc.) */
|
||||
clipLineToNearZ(v1->xyz, v2->xyz, CLIP_DISTANCE, output[0].xyz, &t1);
|
||||
clipLineToNearZ(v1->xyz, v3->xyz, CLIP_DISTANCE, output[2].xyz, &t2);
|
||||
|
||||
|
@ -294,26 +292,25 @@ void clipTriangleStrip(AlignedVector* vertices, AlignedVector* outBuffer) {
|
|||
|
||||
ClipVertex output[4];
|
||||
|
||||
/* FIXME: Interpolate other values (colors etc.) */
|
||||
clipLineToNearZ(v1->xyz, v2->xyz, CLIP_DISTANCE, output[1].xyz, &t1);
|
||||
clipLineToNearZ(v3->xyz, v2->xyz, CLIP_DISTANCE, output[2].xyz, &t2);
|
||||
clipLineToNearZ(v3->xyz, v2->xyz, CLIP_DISTANCE, output[3].xyz, &t2);
|
||||
|
||||
interpolateFloat(v1->w, v2->w, t1, &output[1].w);
|
||||
interpolateFloat(v3->w, v2->w, t2, &output[2].w);
|
||||
interpolateFloat(v3->w, v2->w, t2, &output[3].w);
|
||||
|
||||
output[0] = *v1;
|
||||
output[3] = *v3;
|
||||
output[2] = *v3;
|
||||
|
||||
/* Interpolate normals */
|
||||
interpolateVec3(v1->nxyz, v2->nxyz, t1, output[1].nxyz);
|
||||
interpolateVec3(v3->nxyz, v2->nxyz, t2, output[2].nxyz);
|
||||
interpolateVec3(v3->nxyz, v2->nxyz, t2, output[3].nxyz);
|
||||
|
||||
/* Interpolate texcoords */
|
||||
interpolateVec2(v1->uv, v2->uv, t1, output[1].uv);
|
||||
interpolateVec2(v3->uv, v2->uv, t2, output[2].uv);
|
||||
interpolateVec2(v3->uv, v2->uv, t2, output[3].uv);
|
||||
|
||||
interpolateColour((uint32_t*) &v1->argb, (uint32_t*) &v2->argb, t1, (uint32_t*) &output[1].argb);
|
||||
interpolateColour((uint32_t*) &v3->argb, (uint32_t*) &v2->argb, t2, (uint32_t*) &output[2].argb);
|
||||
interpolateColour((uint32_t*) &v3->argb, (uint32_t*) &v2->argb, t2, (uint32_t*) &output[3].argb);
|
||||
|
||||
output[0].flags = VERTEX_CMD;
|
||||
output[1].flags = VERTEX_CMD;
|
||||
|
|
|
@ -392,7 +392,7 @@ static void divide(AlignedVector* vertices) {
|
|||
ClipVertex* vertex = (ClipVertex*) vertices->data;
|
||||
|
||||
GLsizei i;
|
||||
for(i = 0; i < vertices->size; ++i, ++vertex) {
|
||||
for(i = 0; i < vertices->size; ++i, ++vertex) {
|
||||
vertex->xyz[2] = 1.0f / vertex->w;
|
||||
vertex->xyz[0] *= vertex->xyz[2];
|
||||
vertex->xyz[1] *= vertex->xyz[2];
|
||||
|
|
|
@ -15,3 +15,4 @@ all:
|
|||
$(KOS_MAKE) -C lerabot01 all
|
||||
$(KOS_MAKE) -C zclip all
|
||||
$(KOS_MAKE) -C zclip_triangle all
|
||||
$(KOS_MAKE) -C zclip_trianglestrip all
|
||||
|
|
29
samples/zclip_trianglestrip/Makefile
Normal file
29
samples/zclip_trianglestrip/Makefile
Normal file
|
@ -0,0 +1,29 @@
|
|||
TARGET = zclip_trianglestrip.elf
|
||||
OBJS = main.o
|
||||
|
||||
all: rm-elf $(TARGET)
|
||||
|
||||
include $(KOS_BASE)/Makefile.rules
|
||||
|
||||
clean:
|
||||
-rm -f $(TARGET) $(OBJS) romdisk.*
|
||||
|
||||
rm-elf:
|
||||
-rm -f $(TARGET) romdisk.*
|
||||
|
||||
$(TARGET): $(OBJS) romdisk.o
|
||||
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
|
||||
$(OBJS) romdisk.o $(OBJEXTRA) -lm -lkosutils $(KOS_LIBS)
|
||||
|
||||
romdisk.img:
|
||||
$(KOS_GENROMFS) -f romdisk.img -d romdisk -v
|
||||
|
||||
romdisk.o: romdisk.img
|
||||
$(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o
|
||||
|
||||
run: $(TARGET)
|
||||
$(KOS_LOADER) $(TARGET)
|
||||
|
||||
dist:
|
||||
rm -f $(OBJS) romdisk.o romdisk.img
|
||||
$(KOS_STRIP) $(TARGET)
|
99
samples/zclip_trianglestrip/main.c
Normal file
99
samples/zclip_trianglestrip/main.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gl.h"
|
||||
#include "glu.h"
|
||||
#include "glkos.h"
|
||||
|
||||
|
||||
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
||||
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
||||
{
|
||||
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_LEQUAL); // The Type Of Depth Test To Do
|
||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity(); // Reset The Projection Matrix
|
||||
|
||||
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */
|
||||
void ReSizeGLScene(int Width, int Height)
|
||||
{
|
||||
if (Height == 0) // Prevent A Divide By Zero If The Window Is Too Small
|
||||
Height = 1;
|
||||
|
||||
glViewport(0, 0, Width, Height); // Reset The Current Viewport And Perspective Transformation
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
/* The main drawing function. */
|
||||
void DrawGLScene()
|
||||
{
|
||||
static GLfloat movement = 0.0f;
|
||||
static GLboolean increasing = GL_TRUE;
|
||||
|
||||
if(movement > 10.0) {
|
||||
increasing = GL_FALSE;
|
||||
} else if(movement < -10.0f) {
|
||||
increasing = GL_TRUE;
|
||||
}
|
||||
|
||||
if(increasing) {
|
||||
movement += 0.05f;
|
||||
} else {
|
||||
movement -= 0.05f;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
||||
glLoadIdentity(); // Reset The View
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(0.0f, -1.0f, movement);
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glColor3f(1.0f, 1.0f, 0.0f);
|
||||
glVertex3f(-2.5f, 0.0f, -5.0f);
|
||||
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glVertex3f(-2.5f, 0.0f, 5.0f);
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glVertex3f(2.5f, 0.0f, -5.0f);
|
||||
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glVertex3f(2.5f, 0.0f, 5.0f);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
// swap buffers to display, since we're double buffered.
|
||||
glKosSwapBuffers();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glKosInit();
|
||||
|
||||
InitGL(640, 480);
|
||||
ReSizeGLScene(640, 480);
|
||||
|
||||
while(1) {
|
||||
DrawGLScene();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
0
samples/zclip_trianglestrip/romdisk/PLACEHOLDER
Normal file
0
samples/zclip_trianglestrip/romdisk/PLACEHOLDER
Normal file
BIN
samples/zclip_trianglestrip/romdisk/facade00.tga
Executable file
BIN
samples/zclip_trianglestrip/romdisk/facade00.tga
Executable file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
BIN
samples/zclip_trianglestrip/romdisk/facade01.tga
Executable file
BIN
samples/zclip_trianglestrip/romdisk/facade01.tga
Executable file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
BIN
samples/zclip_trianglestrip/romdisk/facade02.tga
Executable file
BIN
samples/zclip_trianglestrip/romdisk/facade02.tga
Executable file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
BIN
samples/zclip_trianglestrip/romdisk/floor.tga
Normal file
BIN
samples/zclip_trianglestrip/romdisk/floor.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
Loading…
Reference in New Issue
Block a user