mirror of https://github.com/aap/librw.git
fixed bug in im3d; worked on resizing windows
This commit is contained in:
parent
7273afb9a3
commit
9609a91848
|
@ -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)){
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue