Home c++ C++, OpenGL - Texture Color Dimming With Figure Color

C++, OpenGL – Texture Color Dimming With Figure Color

Author

Date

Category

wrote on the OpenGL-E code of the texture when I show the texture separately, then everything goes well and when I draw another figure along with the texture, on the example of quadratrat and the color of the square blue, then the texture is painted in blue!

Loading code texture:

texture = img_load (path.c_str ());
If (texture- & gt; Format- & gt; BitsPerpixel & gt; = 4)
  Mode = GL_RGBA;
ELSE.
  MODE = GL_RGB;
id = currentcount;
GlbindTexture (GL_TEXTURE_2D, TEXTURES [CURRENTCOUNT]);
CURRENTCOUNT ++;
glteximage2d (GL_TEXTURE_2D, 0, MODE, TEXTURE- & GT; W,
  Texture- & gt; h, 0, mode, gl_unsign_byte, texture- & gt; pixels);
gltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
gltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, PARAM);
gltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, PARAM);

Texture display code:

glpushmatrix ();
  Glenable (GL_TEXTURE_2D);
  Glenable (GL_BLEND);
  GLBLENDFUNC (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  gltranslatef (position.x, position.y, 0);
  glrotatef (angle, 0, 0, 1);
  gltranslatef (-position.x, -position.y, 0);
  gltranslatef (position.x, position.y, 0);
  GlbindTexture (GL_TEXTURE_2D, TEXTURES [ID]);
  glbegin (GL_POLYGON);
    GLTEXCOORD2F (0, 0); Sprite.getpoint (0);
    GLTEXCOORD2F (1, 0); SPRITE.GETPOINT (1);
    gltexcoord2f (1, 1); Sprite.getpoint (2);
    gltexcoord2f (0, 1); SPRITE.GETPOINT (3);
  Glend ();
  GlDisable (GL_BLEND);
  GlDisable (GL_TEXTURE_2D);
  glpopmatrix ();

How to fix?


Answer 1, Authority 100%

Well, everything is true, there is no code in your example, but in fact, you say OpenGL – “Prepare, now these polygons I will draw blue” and oddly enough, and insensitive, and texture pixels are drawn equally blue. Only in the case of the texture, its blue canal is taken.

Either paint separately with different colors, or the blue square is also from the blue pixels textures and draw everything “white”.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions