Non-Quadratic OpenGL Textures

I am a little new to OpenGL. I am making a 2D application and I have defined a Quad class that defines a square with a texture on it. He loads these textures from a texture atlas, and he does it right. Everything works with regular textures, and the textures are displayed correctly, but not displayed correctly when the texture image is not a square.

For example, I want the Square to have a star texture and a star to appear, and the area around the star-shaped image that is still in the Square will be transparent. But what ultimately happens is that the star looks great, and then there’s another texture behind it from my texture atlas filling the Quad. I assume that the texture behind it is just the last texture loaded into the system? In any case, I do not want this texture to be displayed.

Here is what I mean. I want a star, but not a cloudy texture behind it, to appear:
enter image description here

An important part of my rendering function is:

glDisable(GL_CULL_FACE);
glVertexPointer(vertexStride, GL_FLOAT, 0, vertexes);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(colorStride, GL_FLOAT, 0, colors);   
glEnableClientState(GL_COLOR_ARRAY);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, uvCoordinates);

//render
glDrawArrays(renderStyle, 0, vertexCount);  
+3
source share
3 answers

, RGBA , , - ( - ).

+3

. Photoshop - , gimp - . OpenGL . , .

- . , , -. , , 32- (RGBA - , , , ), 24- (RGB - , , ).

.

, , , /. - , .

+1

You want to call glBindTexture (GL_TEXTURE_2D, 0); after you mapped your texture here is an example from some code written

         // Bind the texture
    glBindTexture(GL_TEXTURE_2D, image.getID());

    // Draw a QUAD with setting texture coordinates
    glBegin(GL_QUADS);
    {
        // Top left corner of the texture
        glTexCoord2f(0, 0);
        glVertex2f(x, y);

        // Top right corner of the texture
        glTexCoord2f(image.getRelativeWidth(), 0);
        glVertex2f(x+image.getImageWidth(), y);

        // Bottom right corner of the texture
        glTexCoord2f(image.getRelativeWidth(), image.getRelativeHeight());
        glVertex2f(x+image.getImageWidth()-20, y+image.getImageHeight());

        // Bottom left corner of the texture
        glTexCoord2f(0, image.getRelativeHeight());
        glVertex2f(x+20, y+image.getImageHeight());
    }
    glEnd();
    glBindTexture(GL_TEXTURE_2D, 0);

I am not an expert, but it certainly decided what you are experiencing for me.

0
source

All Articles