From: <vin...@us...> - 2014-01-13 22:16:09
|
Revision: 15060 http://sourceforge.net/p/supertuxkart/code/15060 Author: vincentlj Date: 2014-01-13 22:16:04 +0000 (Mon, 13 Jan 2014) Log Message: ----------- Characters are now black again. Modified Paths: -------------- main/trunk/src/graphics/glwrap.cpp Added Paths: ----------- main/trunk/data/shaders/colortexturedquad.frag main/trunk/data/shaders/colortexturedquad.vert Added: main/trunk/data/shaders/colortexturedquad.frag =================================================================== --- main/trunk/data/shaders/colortexturedquad.frag (rev 0) +++ main/trunk/data/shaders/colortexturedquad.frag 2014-01-13 22:16:04 UTC (rev 15060) @@ -0,0 +1,10 @@ +#version 130 +uniform sampler2D texture; + +in vec2 uv; +in vec4 col; + +void main() +{ + gl_FragColor = texture2D(texture, uv) * col; +} Added: main/trunk/data/shaders/colortexturedquad.vert =================================================================== --- main/trunk/data/shaders/colortexturedquad.vert (rev 0) +++ main/trunk/data/shaders/colortexturedquad.vert 2014-01-13 22:16:04 UTC (rev 15060) @@ -0,0 +1,18 @@ +#version 130 +uniform vec2 center; +uniform vec2 size; +uniform vec2 texcenter; +uniform vec2 texsize; + +in vec2 position; +in vec2 texcoord; +in ivec4 color; +out vec2 uv; +out vec4 col; + +void main() +{ + col = vec4(color) / 255.; + uv = texcoord * texsize + texcenter; + gl_Position = vec4(position * size + center, 0., 1.); +} Modified: main/trunk/src/graphics/glwrap.cpp =================================================================== --- main/trunk/src/graphics/glwrap.cpp 2014-01-13 18:59:59 UTC (rev 15059) +++ main/trunk/src/graphics/glwrap.cpp 2014-01-13 22:16:04 UTC (rev 15060) @@ -53,6 +53,7 @@ #endif static GLuint quad_buffer; +static GLuint ColoredVertex; static bool is_gl_init = false; // Please leave this code, it's for debugging purpose @@ -186,6 +187,17 @@ glGenBuffers(1, &quad_buffer); glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + + const int quad_color[] = { + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + }; + glGenBuffers(1, &ColoredVertex); + glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(int), quad_color, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -286,6 +298,97 @@ static GLuint TexturedQuadUniformTexcenter; static GLuint TexturedQuadUniformTexsize; +static GLuint ColorTexturedQuadShader; +static GLuint ColorTexturedQuadAttribPosition; +static GLuint ColorTexturedQuadAttribTexCoord; +static GLuint ColorTexturedQuadAttribColor; +static GLuint ColorTexturedQuadUniformTexture; +static GLuint ColorTexturedQuadUniformCenter; +static GLuint ColorTexturedQuadUniformSize; +static GLuint ColorTexturedQuadUniformTexcenter; +static GLuint ColorTexturedQuadUniformTexsize; + +static void drawTexColoredQuad(const video::ITexture *texture, const video::SColor *col, float width, float height, + float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y, + float tex_width, float tex_height) +{ + int colors[] = { + col[0].getRed(), col[0].getGreen(), col[0].getBlue(), col[0].getAlpha(), + col[1].getRed(), col[1].getGreen(), col[1].getBlue(), col[1].getAlpha(), + col[2].getRed(), col[2].getGreen(), col[2].getBlue(), col[2].getAlpha(), + col[3].getRed(), col[3].getGreen(), col[3].getBlue(), col[3].getAlpha(), + }; + if (!ColorTexturedQuadShader) { + ColorTexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), file_manager->getAsset("shaders/colortexturedquad.frag").c_str()); + + ColorTexturedQuadAttribPosition = glGetAttribLocation(ColorTexturedQuadShader, "position"); + ColorTexturedQuadAttribTexCoord = glGetAttribLocation(ColorTexturedQuadShader, "texcoord"); + ColorTexturedQuadAttribColor = glGetAttribLocation(ColorTexturedQuadShader, "color"); + ColorTexturedQuadUniformTexture = glGetUniformLocation(ColorTexturedQuadShader, "texture"); + ColorTexturedQuadUniformCenter = glGetUniformLocation(ColorTexturedQuadShader, "center"); + ColorTexturedQuadUniformSize = glGetUniformLocation(ColorTexturedQuadShader, "size"); + ColorTexturedQuadUniformTexcenter = glGetUniformLocation(ColorTexturedQuadShader, "texcenter"); + ColorTexturedQuadUniformTexsize = glGetUniformLocation(ColorTexturedQuadShader, "texsize"); + } + glUseProgram(ColorTexturedQuadShader); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName()); + glUniform1i(ColorTexturedQuadUniformTexture, 0); + glUniform2f(ColorTexturedQuadUniformCenter, center_pos_x, center_pos_y); + glUniform2f(ColorTexturedQuadUniformSize, width, height); + glUniform2f(ColorTexturedQuadUniformTexcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(ColorTexturedQuadUniformTexsize, tex_width, tex_height); + glEnableVertexAttribArray(ColorTexturedQuadAttribPosition); + glEnableVertexAttribArray(ColorTexturedQuadAttribTexCoord); + glEnableVertexAttribArray(ColorTexturedQuadAttribColor); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(ColorTexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(ColorTexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex); + glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(int), colors); + glVertexAttribPointer(ColorTexturedQuadAttribColor, 4, GL_UNSIGNED_INT, GL_FALSE, 4 * sizeof(float), 0); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDisableVertexAttribArray(ColorTexturedQuadAttribPosition); + glDisableVertexAttribArray(ColorTexturedQuadAttribTexCoord); + glDisableVertexAttribArray(ColorTexturedQuadAttribColor); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void drawTexQuad(const video::ITexture *texture, float width, float height, + float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y, + float tex_width, float tex_height) +{ + if (!TexturedQuadShader) { + TexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/texturedquad.vert").c_str(), file_manager->getAsset("shaders/texturedquad.frag").c_str()); + + TexturedQuadAttribPosition = glGetAttribLocation(TexturedQuadShader, "position"); + TexturedQuadAttribTexCoord = glGetAttribLocation(TexturedQuadShader, "texcoord"); + TexturedQuadUniformTexture = glGetUniformLocation(TexturedQuadShader, "texture"); + TexturedQuadUniformCenter = glGetUniformLocation(TexturedQuadShader, "center"); + TexturedQuadUniformSize = glGetUniformLocation(TexturedQuadShader, "size"); + TexturedQuadUniformTexcenter = glGetUniformLocation(TexturedQuadShader, "texcenter"); + TexturedQuadUniformTexsize = glGetUniformLocation(TexturedQuadShader, "texsize"); + } + glUseProgram(TexturedQuadShader); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName()); + glUniform1i(TexturedQuadUniformTexture, 0); + glUniform2f(TexturedQuadUniformCenter, center_pos_x, center_pos_y); + glUniform2f(TexturedQuadUniformSize, width, height); + glUniform2f(TexturedQuadUniformTexcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(TexturedQuadUniformTexsize, tex_width, tex_height); + glEnableVertexAttribArray(TexturedQuadAttribPosition); + glEnableVertexAttribArray(TexturedQuadAttribTexCoord); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(TexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(TexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDisableVertexAttribArray(TexturedQuadAttribPosition); + glDisableVertexAttribArray(TexturedQuadAttribTexCoord); + glBindBuffer(GL_ARRAY_BUFFER, 0); + +} + void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect, const video::SColor* const colors, bool useAlphaChannelOfTexture) @@ -345,34 +448,12 @@ glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); } - if (!TexturedQuadShader) { - TexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/texturedquad.vert").c_str(), file_manager->getAsset("shaders/texturedquad.frag").c_str()); - - TexturedQuadAttribPosition = glGetAttribLocation(TexturedQuadShader, "position"); - TexturedQuadAttribTexCoord = glGetAttribLocation(TexturedQuadShader, "texcoord"); - TexturedQuadUniformTexture = glGetUniformLocation(TexturedQuadShader, "texture"); - TexturedQuadUniformCenter = glGetUniformLocation(TexturedQuadShader, "center"); - TexturedQuadUniformSize = glGetUniformLocation(TexturedQuadShader, "size"); - TexturedQuadUniformTexcenter = glGetUniformLocation(TexturedQuadShader, "texcenter"); - TexturedQuadUniformTexsize = glGetUniformLocation(TexturedQuadShader, "texsize"); - } - glUseProgram(TexturedQuadShader); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName()); - glUniform1i(TexturedQuadUniformTexture, 0); - glUniform2f(TexturedQuadUniformCenter, center_pos_x, center_pos_y); - glUniform2f(TexturedQuadUniformSize, width, height); - glUniform2f(TexturedQuadUniformTexcenter, tex_center_pos_x, tex_center_pos_y); - glUniform2f(TexturedQuadUniformTexsize, tex_width, tex_height); - glEnableVertexAttribArray(TexturedQuadAttribPosition); - glEnableVertexAttribArray(TexturedQuadAttribTexCoord); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(TexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(TexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glDisableVertexAttribArray(TexturedQuadAttribPosition); - glDisableVertexAttribArray(TexturedQuadAttribTexCoord); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if (colors) + drawTexColoredQuad(texture, colors, width, height, center_pos_x, center_pos_y, + tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); + else + drawTexQuad(texture, width, height, center_pos_x, center_pos_y, + tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); } static GLuint ColoredQuadShader; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-14 01:05:07
|
Revision: 15068 http://sourceforge.net/p/supertuxkart/code/15068 Author: vincentlj Date: 2014-01-14 01:05:03 +0000 (Tue, 14 Jan 2014) Log Message: ----------- Fix colortexturedquad shader/vertexpointer. Modified Paths: -------------- main/trunk/data/shaders/colortexturedquad.vert main/trunk/src/graphics/glwrap.cpp main/trunk/src/graphics/glwrap.hpp Modified: main/trunk/data/shaders/colortexturedquad.vert =================================================================== --- main/trunk/data/shaders/colortexturedquad.vert 2014-01-14 00:11:59 UTC (rev 15067) +++ main/trunk/data/shaders/colortexturedquad.vert 2014-01-14 01:05:03 UTC (rev 15068) @@ -6,7 +6,7 @@ in vec2 position; in vec2 texcoord; -in ivec4 color; +in uvec4 color; out vec2 uv; out vec4 col; Modified: main/trunk/src/graphics/glwrap.cpp =================================================================== --- main/trunk/src/graphics/glwrap.cpp 2014-01-14 00:11:59 UTC (rev 15067) +++ main/trunk/src/graphics/glwrap.cpp 2014-01-14 01:05:03 UTC (rev 15068) @@ -51,6 +51,7 @@ PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; PFNGLTEXBUFFERPROC glTexBuffer; PFNGLBUFFERSUBDATAPROC glBufferSubData; +PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; #endif static GLuint quad_buffer; @@ -176,6 +177,7 @@ glUniform1fv = (PFNGLUNIFORM1FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform1fv"); glUniform4fv = (PFNGLUNIFORM4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fv"); glBufferSubData = (PFNGLBUFFERSUBDATAPROC)IRR_OGL_LOAD_EXTENSION("glBufferSubData"); + glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)IRR_OGL_LOAD_EXTENSION("glVertexAttribIPointer"); #endif #ifdef ENABLE_ARB_DEBUG_OUTPUT glDebugMessageCallbackARB(debugCallback, NULL); @@ -190,15 +192,15 @@ glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); - const int quad_color[] = { - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, + const unsigned quad_color[] = { + 0, 0, 0, 255, + 255, 0, 0, 255, + 0, 255, 0, 255, + 0, 0, 255, 255, }; glGenBuffers(1, &ColoredVertex); glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(int), quad_color, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -318,12 +320,13 @@ float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height) { - int colors[] = { + unsigned colors[] = { col[0].getRed(), col[0].getGreen(), col[0].getBlue(), col[0].getAlpha(), col[1].getRed(), col[1].getGreen(), col[1].getBlue(), col[1].getAlpha(), col[2].getRed(), col[2].getGreen(), col[2].getBlue(), col[2].getAlpha(), col[3].getRed(), col[3].getGreen(), col[3].getBlue(), col[3].getAlpha(), }; + if (!ColorTexturedQuadShader) { ColorTexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), file_manager->getAsset("shaders/colortexturedquad.frag").c_str()); @@ -344,11 +347,11 @@ glVertexAttribPointer(ColorTexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); glVertexAttribPointer(ColorTexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex); - glVertexAttribPointer(ColorTexturedQuadAttribColor, 4, GL_UNSIGNED_INT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribIPointer(ColorTexturedQuadAttribColor, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); glBindVertexArray(0); } glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex); - glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(int), colors); + glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(unsigned), colors); glUseProgram(ColorTexturedQuadShader); glBindVertexArray(CTQvao); glActiveTexture(GL_TEXTURE0); Modified: main/trunk/src/graphics/glwrap.hpp =================================================================== --- main/trunk/src/graphics/glwrap.hpp 2014-01-14 00:11:59 UTC (rev 15067) +++ main/trunk/src/graphics/glwrap.hpp 2014-01-14 01:05:03 UTC (rev 15068) @@ -74,6 +74,7 @@ extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; extern PFNGLTEXBUFFERPROC glTexBuffer; extern PFNGLBUFFERSUBDATAPROC glBufferSubData; +extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vin...@us...> - 2014-01-14 01:24:33
|
Revision: 15069 http://sourceforge.net/p/supertuxkart/code/15069 Author: vincentlj Date: 2014-01-14 01:24:28 +0000 (Tue, 14 Jan 2014) Log Message: ----------- Light: Simplify slightly shader Modified Paths: -------------- main/trunk/data/shaders/pointlight.frag main/trunk/src/graphics/post_processing.cpp Modified: main/trunk/data/shaders/pointlight.frag =================================================================== --- main/trunk/data/shaders/pointlight.frag 2014-01-14 01:05:03 UTC (rev 15068) +++ main/trunk/data/shaders/pointlight.frag 2014-01-14 01:24:28 UTC (rev 15069) @@ -5,12 +5,13 @@ uniform vec4 col[16]; uniform float energy[16]; uniform float spec; -uniform vec2 screen; uniform mat4 invproj; uniform mat4 viewm; +in vec2 uv; + void main() { - vec2 texc = gl_FragCoord.xy / screen; + vec2 texc = uv; float z = texture2D(ntex, texc).a; vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f; Modified: main/trunk/src/graphics/post_processing.cpp =================================================================== --- main/trunk/src/graphics/post_processing.cpp 2014-01-14 01:05:03 UTC (rev 15068) +++ main/trunk/src/graphics/post_processing.cpp 2014-01-14 01:24:28 UTC (rev 15069) @@ -337,7 +337,7 @@ { GLuint Program = 0; GLuint attrib_position, attrib_texcoord; - GLuint uniform_ntex, uniform_center, uniform_col, uniform_energy, uniform_spec, uniform_screen, uniform_invproj, uniform_viewm; + GLuint uniform_ntex, uniform_center, uniform_col, uniform_energy, uniform_spec, uniform_invproj, uniform_viewm; GLuint vao = 0; @@ -352,7 +352,6 @@ uniform_col = glGetUniformLocation(Program, "col[0]"); uniform_energy = glGetUniformLocation(Program, "energy[0]"); uniform_spec = glGetUniformLocation(Program, "spec"); - uniform_screen = glGetUniformLocation(Program, "screen"); uniform_invproj = glGetUniformLocation(Program, "invproj"); uniform_viewm = glGetUniformLocation(Program, "viewm"); @@ -743,8 +742,6 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy) { - float width = (float)UserConfigParams::m_width; - float height = (float)UserConfigParams::m_height; if (!PointLightShader::Program) PointLightShader::init(); glEnable(GL_BLEND); @@ -759,7 +756,6 @@ glUniform4fv(PointLightShader::uniform_col, 16, colors.data()); glUniform1fv(PointLightShader::uniform_energy, 16, energy.data()); glUniform1f(PointLightShader::uniform_spec, 200); - glUniform2f(PointLightShader::uniform_screen, width, height); glUniformMatrix4fv(PointLightShader::uniform_invproj, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer()); glUniformMatrix4fv(PointLightShader::uniform_viewm, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |