diff --git a/skeleton/glfw.cpp b/skeleton/glfw.cpp index 8a6dc37..bc6e69d 100644 --- a/skeleton/glfw.cpp +++ b/skeleton/glfw.cpp @@ -149,13 +149,25 @@ keypress(GLFWwindow *window, int key, int scancode, int action, int mods) } } +static void +resize(GLFWwindow *window, int w, int h) +{ + rw::Rect r; + r.x = 0; + r.y = 0; + r.w = w; + r.h = h; + EventHandler(RESIZE, &r); +} + int main(int argc, char *argv[]) { args.argc = argc; args.argv = argv; - EventHandler(INITIALIZE, nil); + if(EventHandler(INITIALIZE, nil) == EVENTERROR) + return 0; engineStartParams.width = sk::globals.width; engineStartParams.height = sk::globals.height; @@ -167,6 +179,7 @@ main(int argc, char *argv[]) initkeymap(); glfwSetKeyCallback(window, keypress); + glfwSetWindowSizeCallback(window, resize); float lastTime = glfwGetTime()*1000; while(!sk::globals.quit && !glfwWindowShouldClose(window)){ diff --git a/skeleton/skeleton.cpp b/skeleton/skeleton.cpp index 8261ef6..119dd97 100644 --- a/skeleton/skeleton.cpp +++ b/skeleton/skeleton.cpp @@ -31,6 +31,17 @@ TerminateRW(void) rw::Engine::term(); } +Camera* +CameraCreate(int32 width, int32 height, bool32 z) +{ + Camera *cam; + cam = Camera::create(); + cam->setFrame(Frame::create()); + cam->frameBuffer = Raster::create(width, height, 0, Raster::CAMERA); + cam->zBuffer = Raster::create(width, height, 0, Raster::ZBUFFER); + return cam; +} + void CameraSize(Camera *cam, Rect *r) { diff --git a/skeleton/skeleton.h b/skeleton/skeleton.h index b05961b..be3f3d3 100644 --- a/skeleton/skeleton.h +++ b/skeleton/skeleton.h @@ -92,6 +92,7 @@ extern Args args; bool InitRW(void); void TerminateRW(void); +Camera *CameraCreate(int32 width, int32 height, bool32 z); void CameraSize(Camera *cam, Rect *r); EventStatus EventHandler(Event e, void *param); diff --git a/skeleton/win.cpp b/skeleton/win.cpp index 627760b..c0c2f76 100644 --- a/skeleton/win.cpp +++ b/skeleton/win.cpp @@ -189,7 +189,8 @@ WinMain(HINSTANCE instance, HINSTANCE, */ args.argc = __argc; args.argv = __argv; - EventHandler(INITIALIZE, nil); + if(EventHandler(INITIALIZE, nil) == EVENTERROR) + return 0; HWND win = MakeWindow(instance, sk::globals.width, sk::globals.height, diff --git a/src/camera.cpp b/src/camera.cpp index 94554d9..c03f6e1 100755 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -344,8 +344,7 @@ Camera::clear(RGBA *col, uint32 mode) void Camera::showRaster(void) { - // TODO: camera raster - engine->device.showRaster(nil); + engine->device.showRaster(this->frameBuffer); } void @@ -420,6 +419,7 @@ Camera::frustumTestSphere(Sphere *s) return SPHEREOUTSIDE; if(s->radius > -dist) res = SPHEREBOUNDARY; + p++; } return res; } diff --git a/src/d3d/d3ddevice.cpp b/src/d3d/d3ddevice.cpp index 064f443..ecf1972 100755 --- a/src/d3d/d3ddevice.cpp +++ b/src/d3d/d3ddevice.cpp @@ -480,6 +480,9 @@ static void showRaster(Raster *raster) { // TODO: do this properly! + + // not used but we want cameras to have rasters + assert(raster); d3ddevice->Present(nil, nil, 0, nil); } diff --git a/src/d3d/d3dimmed.cpp b/src/d3d/d3dimmed.cpp index af57fdb..ed5eafe 100644 --- a/src/d3d/d3dimmed.cpp +++ b/src/d3d/d3dimmed.cpp @@ -167,6 +167,7 @@ im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices) memcpy(lockedindices, indices, numIndices*sizeof(uint16)); unlockIndices(im3dindbuf); + d3ddevice->SetIndices(im3dindbuf); d3d::setTexture(0, engine->imtexture); d3d::flushCache(); diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 51f9194..28628a3 100755 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -21,6 +21,12 @@ namespace rw { namespace gl3 { +struct GlGlobals +{ + GLFWwindow *window; + int presentWidth, presentHeight; +} glGlobals; + struct UniformState { int32 alphaFunc; @@ -387,13 +393,11 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode) glClear(mask); } -static GLFWwindow *glfwwindow; - static void showRaster(Raster *raster) { // TODO: do this properly! - glfwSwapBuffers(glfwwindow); + glfwSwapBuffers(glGlobals.window); } static void @@ -465,6 +469,14 @@ beginUpdate(Camera *cam) uniformState.fogEnd = cam->farPlane; stateDirty = 1; } + + int w, h; + glfwGetWindowSize(glGlobals.window, &w, &h); + if(w != glGlobals.presentWidth || h != glGlobals.presentHeight){ + glViewport(0, 0, w, h); + glGlobals.presentWidth = w; + glGlobals.presentHeight = h; + } } static int @@ -507,7 +519,7 @@ openGLFW(EngineStartParams *startparams) glfwTerminate(); return 0; } - glfwwindow = win; + glGlobals.window = win; *startparams->window = win; return 1; } @@ -515,7 +527,7 @@ openGLFW(EngineStartParams *startparams) static int closeGLFW(void) { - glfwDestroyWindow(glfwwindow); + glfwDestroyWindow(glGlobals.window); glfwTerminate(); return 1; } diff --git a/tools/clumpview/main.cpp b/tools/clumpview/main.cpp index 9576934..484146b 100644 --- a/tools/clumpview/main.cpp +++ b/tools/clumpview/main.cpp @@ -206,13 +206,8 @@ InitRW(void) Scene.world->addLight(direct); camera = new Camera; - Scene.camera = rw::Camera::create(); + Scene.camera = sk::CameraCreate(sk::globals.width, sk::globals.height, 1); camera->m_rwcam = Scene.camera; - Scene.camera->frameBuffer = - rw::Raster::create(sk::globals.width, sk::globals.height, 0, rw::Raster::CAMERA); - Scene.camera->zBuffer = - rw::Raster::create(sk::globals.width, sk::globals.height, 0, rw::Raster::ZBUFFER); - Scene.camera->setFrame(rw::Frame::create()); camera->m_aspectRatio = 640.0f/480.0f; camera->m_near = 0.1f; camera->m_far = 450.0f; @@ -401,6 +396,7 @@ AppEventHandler(sk::Event e, void *param) r = (Rect*)param; sk::globals.width = r->w; sk::globals.height = r->h; + // TODO: set aspect ratio if(Scene.camera) sk::CameraSize(Scene.camera, r); break;