1
\$\begingroup\$

I am trying to render an image in the viewPort using symmetry_create = 1 and binding texture to it.

 static const GLfloat vertices[] = {
//vertexdata
        -symmetry_create,
        symmetry_create,
        0.0f,
        //uv
        0.0f, 1.0f,
        symmetry_create,
        symmetry_create,
        0.0f,
        //uv
        1.0f, 1.0f,
        symmetry_create,
        -symmetry_create,
        0.0f,
        //uv
        1.0f, 0.0f,
        -symmetry_create,
        -symmetry_create,
        0.0f,
        //uv
        0.0f, 0.0f};

My vertex shader looks like

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 texCoord;

out vec2 TexCoord;
void main()
{
    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
    TexCoord = texCoord;
}

And fragment shader looks like

#version 330 core

in vec2 TexCoord;
out vec4 frag_color;

uniform sampler2D myTexture;
void main()
{
    frag_color = texture(myTexture, TexCoord);
}

I have setup my vao, vbo and indices correctly and thus I am getting the result as expected (ie: A provided image on the display screen).

Now I would like to draw 'n' number of transparent polygons on the image generated.For each polygon, I have thought of achieving using mouse cursor positions and clicks and render using glDrawArrays(GL_TRIANGLE_FAN, 0, n);.

If I use the same vertex and fragment shaders my result now is black opaque polygons on top of the image. How to achieve transparency and color in the polygons. Do I need to another set of shaders(vertex and frag)?

\$\endgroup\$
  • 1
    \$\begingroup\$ Presumably you've read up on how to configure and use blending states in OpenGL? How have you tried configuring your blending state so far? \$\endgroup\$ – DMGregory Mar 2 at 16:31
  • \$\begingroup\$ Yes I have read after you ave shared the link, tried it using // Enable blending glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); but I dont get any result \$\endgroup\$ – Argha Chakraborty Mar 3 at 8:15
  • \$\begingroup\$ I am using a different vertex and fragment shader for drawing the polygon on top of the texture right now..Is this the correct approach? \$\endgroup\$ – Argha Chakraborty Mar 3 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.