fixed bug in im3d; worked on resizing windows

This commit is contained in:
aap 2017-10-21 22:21:36 +02:00
parent 7273afb9a3
commit 9609a91848
9 changed files with 53 additions and 15 deletions

View File

@ -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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
args.argc = argc; args.argc = argc;
args.argv = argv; args.argv = argv;
EventHandler(INITIALIZE, nil); if(EventHandler(INITIALIZE, nil) == EVENTERROR)
return 0;
engineStartParams.width = sk::globals.width; engineStartParams.width = sk::globals.width;
engineStartParams.height = sk::globals.height; engineStartParams.height = sk::globals.height;
@ -167,6 +179,7 @@ main(int argc, char *argv[])
initkeymap(); initkeymap();
glfwSetKeyCallback(window, keypress); glfwSetKeyCallback(window, keypress);
glfwSetWindowSizeCallback(window, resize);
float lastTime = glfwGetTime()*1000; float lastTime = glfwGetTime()*1000;
while(!sk::globals.quit && !glfwWindowShouldClose(window)){ while(!sk::globals.quit && !glfwWindowShouldClose(window)){

View File

@ -31,6 +31,17 @@ TerminateRW(void)
rw::Engine::term(); 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 void
CameraSize(Camera *cam, Rect *r) CameraSize(Camera *cam, Rect *r)
{ {

View File

@ -92,6 +92,7 @@ extern Args args;
bool InitRW(void); bool InitRW(void);
void TerminateRW(void); void TerminateRW(void);
Camera *CameraCreate(int32 width, int32 height, bool32 z);
void CameraSize(Camera *cam, Rect *r); void CameraSize(Camera *cam, Rect *r);
EventStatus EventHandler(Event e, void *param); EventStatus EventHandler(Event e, void *param);

View File

@ -189,7 +189,8 @@ WinMain(HINSTANCE instance, HINSTANCE,
*/ */
args.argc = __argc; args.argc = __argc;
args.argv = __argv; args.argv = __argv;
EventHandler(INITIALIZE, nil); if(EventHandler(INITIALIZE, nil) == EVENTERROR)
return 0;
HWND win = MakeWindow(instance, HWND win = MakeWindow(instance,
sk::globals.width, sk::globals.height, sk::globals.width, sk::globals.height,

View File

@ -344,8 +344,7 @@ Camera::clear(RGBA *col, uint32 mode)
void void
Camera::showRaster(void) Camera::showRaster(void)
{ {
// TODO: camera raster engine->device.showRaster(this->frameBuffer);
engine->device.showRaster(nil);
} }
void void
@ -420,6 +419,7 @@ Camera::frustumTestSphere(Sphere *s)
return SPHEREOUTSIDE; return SPHEREOUTSIDE;
if(s->radius > -dist) if(s->radius > -dist)
res = SPHEREBOUNDARY; res = SPHEREBOUNDARY;
p++;
} }
return res; return res;
} }

View File

@ -480,6 +480,9 @@ static void
showRaster(Raster *raster) showRaster(Raster *raster)
{ {
// TODO: do this properly! // TODO: do this properly!
// not used but we want cameras to have rasters
assert(raster);
d3ddevice->Present(nil, nil, 0, nil); d3ddevice->Present(nil, nil, 0, nil);
} }

View File

@ -167,6 +167,7 @@ im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices)
memcpy(lockedindices, indices, numIndices*sizeof(uint16)); memcpy(lockedindices, indices, numIndices*sizeof(uint16));
unlockIndices(im3dindbuf); unlockIndices(im3dindbuf);
d3ddevice->SetIndices(im3dindbuf);
d3d::setTexture(0, engine->imtexture); d3d::setTexture(0, engine->imtexture);
d3d::flushCache(); d3d::flushCache();

View File

@ -21,6 +21,12 @@
namespace rw { namespace rw {
namespace gl3 { namespace gl3 {
struct GlGlobals
{
GLFWwindow *window;
int presentWidth, presentHeight;
} glGlobals;
struct UniformState struct UniformState
{ {
int32 alphaFunc; int32 alphaFunc;
@ -387,13 +393,11 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
glClear(mask); glClear(mask);
} }
static GLFWwindow *glfwwindow;
static void static void
showRaster(Raster *raster) showRaster(Raster *raster)
{ {
// TODO: do this properly! // TODO: do this properly!
glfwSwapBuffers(glfwwindow); glfwSwapBuffers(glGlobals.window);
} }
static void static void
@ -465,6 +469,14 @@ beginUpdate(Camera *cam)
uniformState.fogEnd = cam->farPlane; uniformState.fogEnd = cam->farPlane;
stateDirty = 1; 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 static int
@ -507,7 +519,7 @@ openGLFW(EngineStartParams *startparams)
glfwTerminate(); glfwTerminate();
return 0; return 0;
} }
glfwwindow = win; glGlobals.window = win;
*startparams->window = win; *startparams->window = win;
return 1; return 1;
} }
@ -515,7 +527,7 @@ openGLFW(EngineStartParams *startparams)
static int static int
closeGLFW(void) closeGLFW(void)
{ {
glfwDestroyWindow(glfwwindow); glfwDestroyWindow(glGlobals.window);
glfwTerminate(); glfwTerminate();
return 1; return 1;
} }

View File

@ -206,13 +206,8 @@ InitRW(void)
Scene.world->addLight(direct); Scene.world->addLight(direct);
camera = new Camera; camera = new Camera;
Scene.camera = rw::Camera::create(); Scene.camera = sk::CameraCreate(sk::globals.width, sk::globals.height, 1);
camera->m_rwcam = Scene.camera; 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_aspectRatio = 640.0f/480.0f;
camera->m_near = 0.1f; camera->m_near = 0.1f;
camera->m_far = 450.0f; camera->m_far = 450.0f;
@ -401,6 +396,7 @@ AppEventHandler(sk::Event e, void *param)
r = (Rect*)param; r = (Rect*)param;
sk::globals.width = r->w; sk::globals.width = r->w;
sk::globals.height = r->h; sk::globals.height = r->h;
// TODO: set aspect ratio
if(Scene.camera) if(Scene.camera)
sk::CameraSize(Scene.camera, r); sk::CameraSize(Scene.camera, r);
break; break;