; tool) so your best bet would be using that tool to configure the demo.
; If that does not work for some reason, modify this file with care...
-fullscreen = false
-resolution = 1024x768
+fullscreen = true
+resolution = dontcare
bpp = dontcare
zbuffer = dontcare
stencil = dontcare
using namespace engfx_state;
GraphicsInitParameters *load_graphics_context_config(const char *fname) {
- static GraphicsInitParameters gip;
+ static GraphicsInitParameters gip;
gip.x = 640;
gip.y = 480;
gip.bpp = 16;
error("%s: could not load config file", __func__);
return 0;
}
-
+
const ConfigOption *cfgopt;
while((cfgopt = get_next_option())) {
-
+
if(!strcmp(cfgopt->option, "fullscreen")) {
if(!strcmp(cfgopt->str_value, "true")) {
gip.fullscreen = true;
return 0;
}
} else if(!strcmp(cfgopt->option, "resolution")) {
- if(!isdigit(cfgopt->str_value[0])) {
- error("%s: error parsing config file %s", __func__, fname);
- return 0;
- }
- gip.x = atoi(cfgopt->str_value);
-
- char *ptr = cfgopt->str_value;
- while(*ptr && *ptr != 'x') *ptr++;
- if(!*ptr || !*(ptr+1) || !isdigit(*(ptr+1))) {
- error("%s: error parsing config file %s", __func__, fname);
- return 0;
+ if(!strcmp(cfgopt->str_value, "dontcare")) {
+ gip.x = 1024;
+ gip.y = 768;
+ gip.dont_care_flags |= DONT_CARE_SIZE;
+ } else {
+ if(!isdigit(cfgopt->str_value[0])) {
+ error("%s: error parsing config file %s", __func__, fname);
+ return 0;
+ }
+ gip.x = atoi(cfgopt->str_value);
+
+ char *ptr = cfgopt->str_value;
+ while(*ptr && *ptr != 'x') ptr++;
+ if(!*ptr || !*(ptr+1) || !isdigit(*(ptr+1))) {
+ error("%s: error parsing config file %s", __func__, fname);
+ return 0;
+ }
+
+ gip.y = atoi(ptr + 1);
}
-
- gip.y = atoi(ptr + 1);
} else if(!strcmp(cfgopt->option, "bpp")) {
if(cfgopt->flags & CFGOPT_INT) {
gip.bpp = cfgopt->int_value;
} else {
error("%s: error parsing config file %s", __func__, fname);
return 0;
- }
+ }
} else if(!strcmp(cfgopt->option, "zbuffer")) {
if(cfgopt->flags & CFGOPT_INT) {
gip.depth_bits = cfgopt->int_value;
void set_render_target(Texture *tex, CubeMapFace cube_map_face) {
static std::stack<Texture*> rt_stack;
static std::stack<CubeMapFace> face_stack;
-
+
Texture *prev = rt_stack.empty() ? 0 : rt_stack.top();
CubeMapFace prev_face = CUBE_MAP_PX; // just to get rid of the uninitialized var warning
if(!face_stack.empty()) prev_face = face_stack.top();
set_texture(0, prev);
glCopyTexSubImage2D(prev->get_type() == TEX_CUBE ? prev_face : GL_TEXTURE_2D, 0, 0, 0, 0, 0, prev->width, prev->height);
}
-
+
if(!tex) {
rt_stack.pop();
if(prev->get_type() == TEX_CUBE) {
switch(xform_type) {
case XFORM_WORLD:
return world_matrix;
-
+
case XFORM_VIEW:
return view_matrix;
-
+
case XFORM_TEXTURE:
return tex_matrix[num];
-
+
case XFORM_PROJECTION:
default:
return proj_matrix;
}
}
-void set_viewport(unsigned int x, unsigned int y, unsigned int xsize, unsigned int ysize) {
+void set_viewport(unsigned int x, unsigned int y, unsigned int xsize, unsigned int ysize)
+{
glViewport(x, y, xsize, ysize);
}
#define DONT_CARE_BPP 1 // 0001
#define DONT_CARE_DEPTH 2 // 0010
#define DONT_CARE_STENCIL 4 // 0100
+#define DONT_CARE_SIZE 8
struct GraphicsInitParameters {
int x, y;
extern std::list<void (*)(int)> keyb_handlers;
extern std::list<void (*)(int, int)> motion_handlers;
extern std::list<void (*)(int, int, int, int)> button_handlers;
-
+
extern bool button_state[6];
extern int screenx, screeny;
Vector2 get_mouse_pos_normalized();
void set_window_title(const char *title);
+ void show_cursor(bool show);
void swap_buffers();
-
+
int main_loop();
}
glutSetWindowTitle(title);
}
+void fxwt::show_cursor(bool show)
+{
+ glutSetCursor(show ? GLUT_CURSOR_LEFT_ARROW : GLUT_CURSOR_NONE);
+}
+
void fxwt::swap_buffers() {
glutSetWindow(fxwt_glut_win);
glutSwapBuffers();
SDL_WM_SetCaption(title, 0);
}
+void fxwt::show_cursor(bool show)
+{
+ SDL_ShowCursor(show ? 1 : 0);
+}
+
void fxwt::swap_buffers() {
SDL_GL_SwapBuffers();
#if defined(_POSIX_PRIORITY_SCHEDULING)
int fxwt::main_loop() {
set_verbosity(3);
-
+
SDL_EnableKeyRepeat(300, 20);
while(1) {
#include "3dengfx/3denginefx.hpp"
#include "common/err_msg.h"
+#define GOOD_ASPECT(x) ((x) > 1.1f && (x) < 2.0f)
+
bool fxwt::init_graphics(GraphicsInitParameters *gparams) {
info("Initializing SDL");
return false;
}
- if(!gparams->fullscreen) {
- const SDL_VideoInfo *vid_inf = SDL_GetVideoInfo();
+ char driver[128];
+ SDL_VideoDriverName(driver, sizeof driver);
+ info("SDL video driver: %s", driver);
+
+ const SDL_VideoInfo *vid_inf = SDL_GetVideoInfo();
+ if(gparams->fullscreen) {
+ if(gparams->dont_care_flags & DONT_CARE_SIZE) {
+ int curx = vid_inf->current_w;
+ int cury = vid_inf->current_h;
+ float aspect = (float)curx / cury;
+
+ if(!GOOD_ASPECT(aspect)) {
+ SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
+ info("Current mode %dx%d sounds like multi-monitor. Available modes:", curx, cury);
+ for(int i=0; modes[i]; i++) {
+ info(" %dx%d", modes[i]->w, modes[i]->h);
+ aspect = (float)modes[i]->w / modes[i]->h;
+ if(GOOD_ASPECT(aspect) && (modes[i]->w == vid_inf->current_w || modes[i]->h == vid_inf->current_h)) {
+ curx = modes[i]->w;
+ cury = modes[i]->h;
+ }
+ }
+ }
+ gparams->x = curx;
+ gparams->y = cury;
+ }
+ } else {
gparams->bpp = vid_inf->vfmt->BitsPerPixel;
}
info("Trying to set video mode %dx%dx%d, d:%d s:%d %s", gparams->x, gparams->y, gparams->bpp, gparams->depth_bits, gparams->stencil_bits, gparams->fullscreen ? "fullscreen" : "windowed");
-
+
int rbits, gbits, bbits;
switch(gparams->bpp) {
case 32:
rbits = gbits = bbits = 8;
break;
-
+
case 16:
rbits = bbits = 5;
gbits = 6;
break;
-
+
default:
error("%s: Tried to set unsupported pixel format: %d bpp", __func__, gparams->bpp);
return false;
if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) {
if(gparams->depth_bits == 32) gparams->depth_bits = 24;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, gparams->depth_bits);
-
+
if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) {
error("%s: Could not set requested video mode", __func__);
}
error("%s: Could not set requested exact bpp mode", __func__);
return false;
}
-
- // now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for
+
+ // now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for
// exact depth buffer format, however consider 24 and 32 bit the same
if(!(gparams->dont_care_flags & DONT_CARE_DEPTH) && azbits != gparams->depth_bits) {
- if(!(gparams->depth_bits == 32 && azbits == 24 || gparams->depth_bits == 24 && azbits == 32)) {
+ if(!((gparams->depth_bits == 32 && azbits == 24) || (gparams->depth_bits == 24 && azbits == 32))) {
error("%s: Could not set requested exact zbuffer depth", __func__);
return false;
}
#ifdef USING_3DENGFX
#include "3dengfx/3denginefx.hpp"
+#include "fxwt/fxwt.hpp"
#endif // USING_3DENGFX
FrustumPlane::FrustumPlane() {
fov = quarter_pi;
near_clip = 1.0;
far_clip = 10000.0;
- aspect = 1.33333;
+#ifdef USING_3DENGFX
+ aspect = (float)fxwt::screenx / fxwt::screeny;
+#else
+ aspect = 1.33333333;
+#endif
flip_view.x = flip_view.y = flip_view.z = false;
}
}
if(gip->fullscreen) {
- SDL_ShowCursor(0);
+ fxwt::show_cursor(false);
}
fxwt::set_window_title("The Lab Demos :: Summer Hack (rebuild)");
timer_reset(&timer);
timer_start(&timer);
-
+
return true;
}
void clean_up() {
unsigned long time = timer_getmsec(&timer);
-
+
if(music) {
sdlvf_done();
}
- SDL_ShowCursor(1);
+ fxwt::show_cursor(true);
for(size_t i=0; i<parts.size(); i++) {
delete parts[i];