Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL Textures form SDLSurface goes too dark
    text
    copied!<p>I've quite the same problem than this <a href="https://stackoverflow.com/questions/13670259/opengl-texture-goes-too-dark">OpenGl goes too dark</a> but the answer doesn't work for me. I'm trying to display a image thanks to a surface converted to a texture and the result is too damn dark:</p> <p>Original:</p> <p><img src="https://i.stack.imgur.com/YGbNa.png" alt="enter image description here"> </p> <p>after openGL</p> <p><img src="https://i.stack.imgur.com/JyMup.png" alt="enter image description here"></p> <p>On the left is the original, on the right the OpenGl img.</p> <p>Here's my code:</p> <pre><code>void TexturedRect::draw(int scroll){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, _texture); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); //Begining the cube's drawing int x = this-&gt;getX(); int y = this-&gt;getY(); int w = this-&gt;getWidth(); int h = this-&gt;getHeight(); int z = this-&gt;getZ(); /* (0,0) ------ (1,0) | | | | (0,1) ------ (1,1) */ glTexCoord3i(0, 0, 1);glVertex3i(x + scroll, y, z); glTexCoord3i(_tv, 0, 1);glVertex3i(x + w * _tv + scroll, y, z); glTexCoord3i(_tv, _tu, 1);glVertex3i(x + w * _tv + scroll, y + h * _tu, z); glTexCoord3i(0, _tu, 1);glVertex3i(x + scroll, y + h * _tu, z); glEnd(); glDisable(GL_TEXTURE_2D); } void TexturedRect::createTextureFromSurface() { SDL_Surface * surface = IMG_Load(filename.toStdString().c_str()); // get the number of channels in the SDL surface GLint nbOfColors = surface-&gt;format-&gt;BytesPerPixel; GLenum textureFormat = 0; switch (nbOfColors) { case 1: textureFormat = GL_ALPHA; break; case 3: // no alpha channel if (surface-&gt;format-&gt;Rmask == 0x000000ff) textureFormat = GL_RGB; else textureFormat = GL_BGR; break; case 4: // contains an alpha channel if (surface-&gt;format-&gt;Rmask == 0x000000ff) textureFormat = GL_RGBA; else textureFormat = GL_BGRA; break; default: qDebug() &lt;&lt; "Warning: the image is not truecolor..."; break; } glEnable( GL_TEXTURE_2D ); // Have OpenGL generate a texture object handle for us glGenTextures( 1, &amp;_texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, _texture ); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, nbOfColors, surface-&gt;w, surface-&gt;h, 0, textureFormat, GL_UNSIGNED_BYTE, surface-&gt;pixels ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload