# HG changeset patch # User John Tsiombikas # Date 1435470505 -10800 # Node ID d6209903454bb4a144cb87d0aa7ce456f497edbe # Parent b1a195c3ee1689b84e6e425082079c3459a20b47 opengl capabilities diff -r b1a195c3ee16 -r d6209903454b src/game.cc --- a/src/game.cc Sun Jun 28 08:34:24 2015 +0300 +++ b/src/game.cc Sun Jun 28 08:48:25 2015 +0300 @@ -1,5 +1,5 @@ #include -#include +#include "opengl.h" #include "game.h" #include "board.h" #include "scenery.h" @@ -21,23 +21,32 @@ bool game_init() { + if(init_opengl() == -1) { + return false; + } + glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - if(GLEW_ARB_multisample) { + if(glcaps.sep_spec) { + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); + } + + if(glcaps.fsaa) { glEnable(GL_MULTISAMPLE); } - Mesh::use_custom_sdr_attr = false; - - if(!(sdr_phong = create_program_load("sdr/phong.v.glsl", "sdr/phong.p.glsl"))) { - return false; - } - if(!(sdr_phong_notex = create_program_load("sdr/phong.v.glsl", "sdr/phong-notex.p.glsl"))) { - return false; + if(glcaps.shaders) { + Mesh::use_custom_sdr_attr = false; + if(!(sdr_phong = create_program_load("sdr/phong.v.glsl", "sdr/phong.p.glsl"))) { + return false; + } + if(!(sdr_phong_notex = create_program_load("sdr/phong.v.glsl", "sdr/phong-notex.p.glsl"))) { + return false; + } } if(!board.init()) { diff -r b1a195c3ee16 -r d6209903454b src/mesh.cc --- a/src/mesh.cc Sun Jun 28 08:34:24 2015 +0300 +++ b/src/mesh.cc Sun Jun 28 08:48:25 2015 +0300 @@ -564,9 +564,10 @@ void Mesh::draw() const { - int cur_sdr; - glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); - + int cur_sdr = 0; + if(glcaps.shaders) { + glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + } ((Mesh*)this)->update_buffers(); @@ -720,8 +721,10 @@ void Mesh::draw_normals() const { #ifdef USE_OLDGL - int cur_sdr; - glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + int cur_sdr = 0; + if(glcaps.shaders) { + glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + } Vector3 *varr = (Vector3*)get_attrib_data(MESH_ATTR_VERTEX); Vector3 *norm = (Vector3*)get_attrib_data(MESH_ATTR_NORMAL); @@ -756,8 +759,10 @@ void Mesh::draw_tangents() const { #ifdef USE_OLDGL - int cur_sdr; - glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + int cur_sdr = 0; + if(glcaps.shaders) { + glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + } Vector3 *varr = (Vector3*)get_attrib_data(MESH_ATTR_VERTEX); Vector3 *tang = (Vector3*)get_attrib_data(MESH_ATTR_TANGENT); diff -r b1a195c3ee16 -r d6209903454b src/object.cc --- a/src/object.cc Sun Jun 28 08:34:24 2015 +0300 +++ b/src/object.cc Sun Jun 28 08:48:25 2015 +0300 @@ -69,7 +69,9 @@ void Object::set_shader(unsigned int sdr) { - this->sdr = sdr; + if(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { + this->sdr = sdr; + } } void Object::draw() const diff -r b1a195c3ee16 -r d6209903454b src/opengl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.c Sun Jun 28 08:48:25 2015 +0300 @@ -0,0 +1,14 @@ +#include "opengl.h" + +struct GLCaps glcaps; + +int init_opengl() +{ + glewInit(); + + glcaps.shaders = GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader; + glcaps.fsaa = GLEW_ARB_multisample; + glcaps.sep_spec = GLEW_EXT_separate_specular_color; + + return 0; +} diff -r b1a195c3ee16 -r d6209903454b src/opengl.h --- a/src/opengl.h Sun Jun 28 08:34:24 2015 +0300 +++ b/src/opengl.h Sun Jun 28 08:48:25 2015 +0300 @@ -3,4 +3,21 @@ #include +struct GLCaps { + int shaders; + int fsaa; + int sep_spec; +}; +extern struct GLCaps glcaps; + +#ifdef __cplusplus +extern "C" { +#endif + +int init_opengl(); + +#ifdef __cplusplus +} +#endif + #endif /* OPENGL_H_ */