2
\$\begingroup\$

I'm new to OpenGl Faced this problem:

The Glitch

Draw function:

void Renderer::Draw()
{

    glUseProgram(programID);    
    shader.UseProgram();

    mat4 view = mat4(mat3(myCamera->GetViewMatrix()));                                
    glm::mat4 VP = myCamera->GetProjectionMatrix()*myCamera->GetViewMatrix(); 
    shader.BindVPMatrix(&VP[0][0]);                                           

    glm::mat4 VP2 = myCamera->GetProjectionMatrix() * myCamera->GetViewMatrix() * floorM;
    model13D->Render(&shader, scale(100.0f, 100.0f, 100.0f)); // scaling the skybox

    t2->Bind();
    model3D->Render(&shader, scale(2.0f, 2.0f, 2.0f)); //scaling aircraft

    glUniformMatrix4fv(VPID, 1, GL_FALSE, &VP2[0][0]);

    mySquare->Draw();

}

The code of loaded:

    shader.LoadProgram();
    model3D = new Model3D();
    model3D->LoadFromFile("data/models/obj/Galaxy/galaxy.obj", true);
    model3D->Initialize();
    myCamera->SetPerspectiveProjection(90.0f, 4.0f / 3.0f, 0.1f, 10000000.0f);


    model13D = new Model3D();
    model13D->LoadFromFile("data/models/obj/skybox/Skybox.obj", true);
    model13D->Initialize();
    // Projection matrix : 
    //shader.LoadProgram();

    // View matrix : 
    myCamera->Reset(
        +0.0f, +0.0f, 5.0f,// Camera Position
        +0.0f, +0.0f, +0.0f,// Look at Point
        +0.0f, +1.0f, +0.0f // Up Vector
        );
    //////////////////////////////////////////////////////////////////////////
    std::string Images_names[6];

    Images_names[0] = "right.png";
    Images_names[1] = "left.png";
    Images_names[2] = "top.png";
    Images_names[3] = "bottom.png";
    Images_names[4] = "back.png";
    Images_names[5] = "front.png";
    t = new Texture(Images_names, 0);
    t2 = new Texture("arrakisday_dn.tga", 1);
\$\endgroup\$
3
  • \$\begingroup\$ What API are you using? \$\endgroup\$
    – Vaillancourt
    Commented Apr 29, 2017 at 17:28
  • \$\begingroup\$ @Vaillancourt - we can assume from use of glUseProgram and glUniformMatrix4fv in the "Draw program" section, plus the "opengl" tag, that the API is OpenGL. \$\endgroup\$ Commented Apr 29, 2017 at 18:35
  • \$\begingroup\$ @LeComteduMerde-fou Yes, but I believe Model3D and Texture are not; if they're part of another API, it would be nice to know which one. \$\endgroup\$
    – Vaillancourt
    Commented Apr 29, 2017 at 18:37

2 Answers 2

3
\$\begingroup\$

It appears that you either have the wrong texture bound when you attempt to draw the airplane, or you're referencing the wrong texture unit when drawing it.

Some things to check:

  • Are you calling glBindTexture() before drawing the plane? If not, then whatever texture was last bound will still be bound, and it will assume that's the texture you want to use.
  • If you are binding a texture, is it the right one?
  • If it is the right one, is your shader using the same texture unit in its sampling calls?
  • If all the above is correct, then perhaps you're storing all your textures in one big image and you've used the incorrect texture coordinates on the aircraft?
\$\endgroup\$
1
\$\begingroup\$

Normally you want to unbind things as soon as they are finished being used to make it clearer which object is currently bound. After you draw your Sandbox/terrain try to do glBindTexture(gl_texture_target, 0). This will also prevent the wrong texture to be sent to the shader.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .