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);
}
Matrix4x4 create_projection_matrix(scalar_t vfov, scalar_t aspect, scalar_t near_clip, scalar_t far_clip) {
#ifdef COORD_LHS
- scalar_t hfov = vfov * aspect;
- scalar_t w = 1.0f / (scalar_t)tan(hfov * 0.5f);
- scalar_t h = 1.0f / (scalar_t)tan(vfov * 0.5f);
+ scalar_t f = 1.0f / (scalar_t)tan(vfov * 0.5f);
scalar_t q = far_clip / (far_clip - near_clip);
-
+
Matrix4x4 mat;
- mat[0][0] = w;
- mat[1][1] = h;
+ mat[0][0] = f / aspect;
+ mat[1][1] = f;
mat[2][2] = q;
mat[3][2] = 1.0f;
mat[2][3] = -q * near_clip;