From 7a5b8cc4b9f7343db13491941088c95c96833c18 Mon Sep 17 00:00:00 2001 From: Evan Goers Date: Mon, 26 Nov 2012 07:33:32 +0000 Subject: More gl::-ization. --- src/render/dust.cc | 2 +- src/render/gl.cc | 50 ++++++++++++++++++++++++++++++++++++++++++ src/render/gl.h | 23 ++++++++++++++----- src/render/lightenvironment.cc | 14 ++++++------ src/render/state.cc | 4 ++-- src/render/text.cc | 8 +++---- src/render/textures.cc | 34 ++++++++++++++-------------- 7 files changed, 99 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/render/dust.cc b/src/render/dust.cc index fe74536..7358496 100644 --- a/src/render/dust.cc +++ b/src/render/dust.cc @@ -131,7 +131,7 @@ void Dust::draw(math::Color const &dustcolor) } } - glVertex3fv(&dust[i*3]); + gl::vertex(&dust[i*3]); gl::vertex(v); } diff --git a/src/render/gl.cc b/src/render/gl.cc index 8debb8e..b0550da 100644 --- a/src/render/gl.cc +++ b/src/render/gl.cc @@ -114,6 +114,11 @@ void disableclientstate(GLenum cap) glDisableClientState(cap); } +void getinteger(GLenum pname, GLint* params) +{ + glGetIntegerv(pname, params); +} + void clear(GLbitfield mask) { glClear(mask); @@ -178,6 +183,11 @@ void vertex(const float x, const float y, const float z) glVertex3f(x, y, z); } +void vertex(const GLfloat* v) +{ + glVertex3fv(v); +} + void normal(const Vector3f & vector) { glNormal3fv(vector.ptr()); @@ -273,6 +283,26 @@ void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdou glFrustum(left, right, bottom, top, znear, zfar); } +void light(GLenum light, GLenum pname, GLfloat param) +{ + glLightf(light, pname, param); +} + +void light(GLenum light, GLenum pname, GLint param) +{ + glLighti(light, pname, param); +} + +void light(GLenum light, GLenum pname, const GLfloat* params) +{ + glLightfv(light, pname, params); +} + +void light(GLenum light, GLenum pname, const GLint* params) +{ + glLightiv(light, pname, params); +} + void lightmodel(GLenum pname, GLfloat param) { glLightModelf(pname, param); @@ -373,6 +403,26 @@ void texgen(GLenum coord, GLenum param, const GLdouble* value) glTexGendv(coord, param, value); } +void texparameter(GLenum target, GLenum pname, GLfloat param) +{ + glTexParameterf(target, pname, param); +} + +void texparameter(GLenum target, GLenum pname, GLint param) +{ + glTexParameteri(target, pname, param); +} + +void texparameter(GLenum target, GLenum pname, const GLfloat* params) +{ + glTexParameterfv(target, pname, params); +} + +void texparameter(GLenum target, GLenum pname, const GLint* params) +{ + glTexParameteriv(target, pname, params); +} + void activetexture(GLenum texture) { glActiveTexture(texture); diff --git a/src/render/gl.h b/src/render/gl.h index 8d8e48e..2d19a45 100644 --- a/src/render/gl.h +++ b/src/render/gl.h @@ -122,6 +122,9 @@ void enableclientstate(GLenum cap); /// glDisableClientState void disableclientstate(GLenum cap); +/// glGetIntegerv +void getinteger(GLenum pname, GLint* params); + /// glShadeModel void shademodel(GLenum mode); @@ -163,13 +166,11 @@ void end(); * line, and polygon vertices. The current color, normal, and texture * coordinates are associated with the vertex when vertex() is called. */ -void vertex(const math::Vector3f& vector); - -void vertex(const float x, const float y, const float z); - void vertex(const math::Vector2f& vector); - void vertex(const float x, const float y); +void vertex(const math::Vector3f& vector); +void vertex(const float x, const float y, const float z); +void vertex(const GLfloat* v); /// glTexCoord void texcoord(const float x, const float y); @@ -268,6 +269,12 @@ void loadidentity(); /// Perspective matrix void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar); +/// Light source parameters +void light(GLenum light, GLenum pname, GLfloat param); +void light(GLenum light, GLenum pname, GLint param); +void light(GLenum light, GLenum pname, const GLfloat* params); +void light(GLenum light, GLenum pname, const GLint* params); + /// Light model void lightmodel(GLenum pname, GLfloat param); void lightmodel(GLenum pname, GLint param); @@ -300,6 +307,12 @@ void texgen(GLenum coord, GLenum param, const GLint* value); void texgen(GLenum coord, GLenum param, const GLfloat* value); void texgen(GLenum coord, GLenum param, const GLdouble* value); +/// Texture parameters +void texparameter(GLenum target, GLenum pname, GLfloat param); +void texparameter(GLenum target, GLenum pname, GLint param); +void texparameter(GLenum target, GLenum pname, const GLfloat* params); +void texparameter(GLenum target, GLenum pname, const GLint* params); + /// Active server-side texture void activetexture(GLenum texture); /// Active client-side texture diff --git a/src/render/lightenvironment.cc b/src/render/lightenvironment.cc index 8c65848..1c61762 100644 --- a/src/render/lightenvironment.cc +++ b/src/render/lightenvironment.cc @@ -85,15 +85,15 @@ void LightEnvironment::draw(const math::Vector3f translate) gl_diffuse_light[3] = 1.0f; gl_specular_light[3] = 1.0f; - glLightfv(gl_light_id, GL_POSITION, gl_light_location); - glLightfv(gl_light_id, GL_AMBIENT, gl_ambient_light); - glLightfv(gl_light_id, GL_DIFFUSE, gl_diffuse_light); - glLightfv(gl_light_id, GL_SPECULAR, gl_specular_light); + gl::light(gl_light_id, GL_POSITION, gl_light_location); + gl::light(gl_light_id, GL_AMBIENT, gl_ambient_light); + gl::light(gl_light_id, GL_DIFFUSE, gl_diffuse_light); + gl::light(gl_light_id, GL_SPECULAR, gl_specular_light); // attenuation - glLightf(gl_light_id, GL_CONSTANT_ATTENUATION, light->attenuation()[0]); - glLightf(gl_light_id, GL_LINEAR_ATTENUATION, light->attenuation()[1]); - glLightf(gl_light_id, GL_QUADRATIC_ATTENUATION, light->attenuation()[2]); + gl::light(gl_light_id, GL_CONSTANT_ATTENUATION, light->attenuation()[0]); + gl::light(gl_light_id, GL_LINEAR_ATTENUATION, light->attenuation()[1]); + gl::light(gl_light_id, GL_QUADRATIC_ATTENUATION, light->attenuation()[2]); gl_light_id++; diff --git a/src/render/state.cc b/src/render/state.cc index 83f2704..8cafefe 100644 --- a/src/render/state.cc +++ b/src/render/state.cc @@ -98,11 +98,11 @@ void State::init(int width, int height) con_print << "disabled" << std::endl; // probe maximal number of lights - glGetIntegerv(GL_MAX_LIGHTS, &state_maxlights); + gl::getinteger(GL_MAX_LIGHTS, &state_maxlights); con_debug << " maximum number of OpenGL lights is " << state_maxlights << std::endl; // probe maximal number of texture units - glGetIntegerv(GL_MAX_TEXTURE_UNITS, &state_maxtextureunits); + gl::getinteger(GL_MAX_TEXTURE_UNITS, &state_maxtextureunits); con_debug << " maximum number of OpenGL texture units is " << state_maxtextureunits << std::endl; // Generate VBO diff --git a/src/render/text.cc b/src/render/text.cc index c45357d..1c039ef 100644 --- a/src/render/text.cc +++ b/src/render/text.cc @@ -106,16 +106,16 @@ void Text::draw(const float x, const float y, const char ascii) gl::begin(gl::Quads); - glTexCoord2f(fcol, frow); + gl::texcoord(fcol, frow); gl::vertex(x, y, 0); - glTexCoord2f(fcol + 0.0625f, frow); + gl::texcoord(fcol + 0.0625f, frow); gl::vertex(x + text_fontwidth, y, 0); - glTexCoord2f(fcol + 0.0625f, frow + 0.0625f); + gl::texcoord(fcol + 0.0625f, frow + 0.0625f); gl::vertex(x + text_fontwidth, y + text_fontheight, 0); - glTexCoord2f(fcol, frow + 0.0625f); + gl::texcoord(fcol, frow + 0.0625f); gl::vertex(x, y + text_fontheight, 0); gl::end(); diff --git a/src/render/textures.cc b/src/render/textures.cc index ab490a6..e4bfe7f 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -251,14 +251,14 @@ void Textures::load_cubemap(const std::string & name) glBindTexture(GL_TEXTURE_CUBE_MAP, textures_cubemap_id); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0); + gl::texparameter(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0); for (size_t i = 0; i < 6; i++) { if (cube_texture[i]) { @@ -322,10 +322,10 @@ size_t Textures::load(const std::string &name, const bool filter) if (filter) { // scaling functions - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // 4 levels of mipmaps - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); if (r_mipmap->value()) { // hardware generated mipmaps (requires OpenGL 1.4) @@ -333,19 +333,19 @@ size_t Textures::load(const std::string &name, const bool filter) } // enable texture wrapping - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } else { // scaling functions - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // no mipmaps, base level only - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl::texparameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + //gl::texenv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (image->channels() == 4) { texture_format = GL_RGBA; -- cgit v1.2.3