diff --git a/src/O3DGlideRenderer.m b/src/O3DGlideRenderer.m index f3a2e34..f917b7d 100644 --- a/src/O3DGlideRenderer.m +++ b/src/O3DGlideRenderer.m @@ -171,10 +171,13 @@ grGlideShutdownCdecl(void) #endif if (!grSstWinOpen(hWnd, sizeToScreenResolution(resolution), - floatToScreenRefresh(refreshRate), GR_COLORFORMAT_RGBA, + floatToScreenRefresh(refreshRate), GR_COLORFORMAT_ARGB, GR_ORIGIN_LOWER_LEFT, 2, 1)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; + + grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); + grDepthMask(FXTRUE); } @catch (id e) { [self release]; @throw e; @@ -196,7 +199,7 @@ grGlideShutdownCdecl(void) - (void)beginFrame { - grBufferClear(0, 0, 0); + grBufferClear(0, 0, GR_WDEPTHVALUE_FARTHEST); } - (void)drawPolygonWithVertices: (const O3DVertex *)vertices @@ -216,10 +219,10 @@ grGlideShutdownCdecl(void) (vertices[i].position.x + 1) * halfWidth; glideVertices[i].y = (vertices[i].position.y + 1) * halfHeight; + glideVertices[i].oow = 1.f / vertices[i].position.z; glideVertices[i].r = vertices[i].color.r * 255; glideVertices[i].g = vertices[i].color.g * 255; glideVertices[i].b = vertices[i].color.b * 255; - glideVertices[i].a = vertices[i].color.a * 255; } grDrawPolygonVertexList((int)count, glideVertices); diff --git a/src/O3DRenderer.h b/src/O3DRenderer.h index 99ea0ac..48ab208 100644 --- a/src/O3DRenderer.h +++ b/src/O3DRenderer.h @@ -19,10 +19,10 @@ OF_ASSUME_NONNULL_BEGIN typedef struct OF_BOXABLE { struct { - float x, y; + float x, y, z; } position; struct { - float r, g, b, a; + float r, g, b; } color; } O3DVertex; diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m index b42c770..af40031 100644 --- a/tests/TestsAppDelegate.m +++ b/tests/TestsAppDelegate.m @@ -32,21 +32,21 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate) options: nil] autorelease]; const O3DVertex outerTriangle[] = { - {{ -1, -1 }, { 1, 0, 0 }}, - {{ 0, 1 }, { 0, 1, 0 }}, - {{ 1, -1 }, { 0, 0, 1 }} + {{ -1, -1, 1 }, { 1, 0, 0 }}, + {{ 0, 1, 1 }, { 0, 1, 0 }}, + {{ 1, -1, 1 }, { 0, 0, 1 }} }; const O3DVertex innerTriangle[] = { - {{ -0.5, 0.5 }, { 1, 1, 0 }}, - {{ 0, -0.5 }, { 0, 1, 1 }}, - {{ 0.5, 0.5 }, { 1, 0, 1 }} + {{ -0.5, 0.5, 0 }, { 1, 1, 0 }}, + {{ 0, -0.5, 0 }, { 0, 1, 1 }}, + {{ 0.5, 0.5, 0 }, { 1, 0, 1 }} }; OFDate *startDate = [OFDate date]; while (-startDate.timeIntervalSinceNow < 5) { [renderer beginFrame]; - [renderer drawPolygonWithVertices: outerTriangle count: 3]; [renderer drawPolygonWithVertices: innerTriangle count: 3]; + [renderer drawPolygonWithVertices: outerTriangle count: 3]; [renderer endFrame]; }