Commit 14ee963c authored by Sylvain Thery's avatar Sylvain Thery

OGL3 texture bug correction

parent 87fcb3c9
......@@ -130,9 +130,9 @@ void MyQT::cb_initGL()
m_sprite->setAttributePosition(m_positionVBO);
m_sprite->setColor(Geom::Vec4f(1.0f, 0.0f , 0.0f, 1.0f));
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo();
m_strings->sendToVBO();
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo();
m_strings->sendToVBO();
// copy de contenu de VBO a la creation
m_dataVBO = new Utils::VBO(*m_positionVBO);
......
......@@ -6,5 +6,5 @@ uniform vec4 color;
FRAG_OUT_DEF;
void main (void)
{
float lum = TEXTURE2D(FontTexture, tex_coord).s;;
float lum = TEXTURE2D(FontTexture, tex_coord).s;
// no } because it is added in the shader class code (with other things)
......@@ -62,9 +62,12 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc, bool with_plan
glGenTextures(1, &(*m_idTexture));
glBindTexture(GL_TEXTURE_2D, *m_idTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, WIDTHTEXTURE, HEIGHTTEXTURE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (GLvoid*)(buff));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, WIDTHTEXTURE, HEIGHTTEXTURE, 0, GL_RED, GL_UNSIGNED_BYTE, (GLvoid*)(buff));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
delete[] buff;
}
else
......@@ -88,12 +91,13 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc, bool with_plan
else
{
std::stringstream ss;
ss << "vec4 backColor = vec4(" <<bgc[0] << "," << bgc[1] << "," << bgc[2] << ",color[3]);\n";
// ss << "vec4 backColor = vec4(0.2,0.1,0.4);\n";
ss << " vec4 backColor = vec4(" <<bgc[0] << "," << bgc[1] << "," << bgc[2] << ",color[3]);\n";
glxfrag.append(ss.str());
glxfrag.append(fragmentShaderText3);
}
std::cout << glxfrag << std::endl;
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
m_vbo1 = new Utils::VBO();
......@@ -178,6 +182,7 @@ unsigned int Strings3D::sendOneStringToVBO(const std::string& str, float **buffe
float u2 = u + float(REALWIDTHFONT) / float(WIDTHTEXTURE);
float v2 = v + float(WIDTHFONT - 1) / float(HEIGHTTEXTURE);
// 0
*buffer++ = x;
*buffer++ = 0;
*buffer++ = u;
......@@ -185,16 +190,31 @@ unsigned int Strings3D::sendOneStringToVBO(const std::string& str, float **buffe
float xf = x + float(REALWIDTHFONT) / 25.f;
// 1
*buffer++ = xf;
*buffer++ = 0;
*buffer++ = u2;
*buffer++ = v2;
// 2
*buffer++ = xf;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u2;
*buffer++ = v;
// 0
*buffer++ = x;
*buffer++ = 0;
*buffer++ = u;
*buffer++ = v2;
// 2
*buffer++ = xf;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u2;
*buffer++ = v;
// 3
*buffer++ = x;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u;
......@@ -205,7 +225,7 @@ unsigned int Strings3D::sendOneStringToVBO(const std::string& str, float **buffe
*buffervbo = buffer;
return 4 * nbc;
return 6 * nbc;
}
void Strings3D::sendToVBO()
......@@ -214,7 +234,7 @@ void Strings3D::sendToVBO()
// alloc buffer
m_vbo1->bind();
glBufferData(GL_ARRAY_BUFFER, m_nbChars * 16 * sizeof(float), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, m_nbChars * 24 * sizeof(float), 0, GL_STREAM_DRAW);
float* buffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
// fill buffer
......@@ -269,7 +289,7 @@ void Strings3D::postdraw()
void Strings3D::draw(unsigned int idSt, const Geom::Vec3f& pos)
{
glUniform3fv(*m_uniform_position, 1, pos.data());
glDrawArrays(GL_QUADS, m_strpos[idSt].first , m_strpos[idSt].second );
glDrawArrays(GL_TRIANGLES, m_strpos[idSt].first , m_strpos[idSt].second );
}
void Strings3D::drawAll(const Geom::Vec4f& color)
......@@ -290,7 +310,7 @@ void Strings3D::drawAll(const Geom::Vec4f& color)
for (unsigned int idSt=0; idSt<nb; ++idSt)
{
glUniform3fv(*m_uniform_position, 1, m_strTranslate[idSt].data());
glDrawArrays(GL_QUADS, m_strpos[idSt].first , m_strpos[idSt].second );
glDrawArrays(GL_TRIANGLES, m_strpos[idSt].first , m_strpos[idSt].second );
}
postdraw();
}
......@@ -316,23 +336,38 @@ void Strings3D::updateString(unsigned int idSt, const std::string& str)
float u2 = u + float(REALWIDTHFONT) / float(WIDTHTEXTURE);
float v2 = v + float(WIDTHFONT - 1) / float(HEIGHTTEXTURE);
// 0
*buffer++ = x;
*buffer++ = 0;
*buffer++ = u;
*buffer++ = v2;
float xf = x + float(REALWIDTHFONT) / 25.f;
// 1
*buffer++ = xf;
*buffer++ = 0;
*buffer++ = u2;
*buffer++ = v2;
// 2
*buffer++ = xf;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u2;
*buffer++ = v;
// 0
*buffer++ = x;
*buffer++ = 0;
*buffer++ = u;
*buffer++ = v2;
// 2
*buffer++ = xf;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u2;
*buffer++ = v;
// 3
*buffer++ = x;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u;
......
......@@ -86,7 +86,7 @@ void TextureSticker::fullScreenTexture(CGoGNGLuint texId)
// Draw quad
sm_textureMappingShader->enableVertexAttribs();
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
sm_textureMappingShader->disableVertexAttribs();
// Unbind texture mapping shader
......@@ -134,7 +134,7 @@ void TextureSticker::fullScreenTextureDepth(CGoGNGLuint texId, CGoGNGLuint dtexI
// Draw quad
sm_depthtextureMappingShader->enableVertexAttribs();
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
sm_depthtextureMappingShader->disableVertexAttribs();
// Unbind texture mapping shader
......@@ -175,7 +175,7 @@ void TextureSticker::fullScreenShader(Utils::GLSLShader* shader)
// Draw quad
shader->enableVertexAttribs();
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
shader->disableVertexAttribs();
// Unbind shader
......
......@@ -78,7 +78,10 @@ Dependencies
------------
* install (or compile) Qt (choose 32/64 bits)
* install python 2.7 (choose 32/64 bits) (Needed for SCHNApps)
* Other Windows dependencies are furnished at http://cgogn.unistra.fr/Dependencies/
* Other Windows dependencies are furnished at:
- http://cgogn.unistra.fr/Dependencies/dependencies.txt
- http://cgogn.unistra.fr/Dependencies/windows_dependencies32.zip
- http://cgogn.unistra.fr/Dependencies/windows_dependencies64.zip
**Supported compilers: Visual C++ 2013 (12.0) or greater**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment