2017-05-13 2 views
-1

Pour ma 2D, opengl/jeu sdl Je suis actuellement en cours d'exécution d'un fichier journal opengl qui imprime les propriétés du programme openGL suivantes:openGL emplacement d'attribut uniforme invalide

GL_LINK_STATUS = SUCCESS 
GL_ATTACHED_SHADERS = 0 
GL_ACTIVE_ATTRIBUTES = 2 
- 0) type:vec2 name:textCoord location 1 
- 1) type:vec3 name:vertexPosition location 0 
GL_ACTIVE_UNIFORMS = 1 
- 0) type:sampler2D name:basicTexture location -1 

Comme vous pouvez le voir, à la fois ma position et Les attributs de coordonnées de texture sont actifs et fonctionnent, mais mon attribut uniforme indique un emplacement de -1 (ce que je suppose suppose un emplacement incorrect). J'essaie de charger correctement ma première texture. Avant d'essayer d'afficher une texture, j'ai pu faire apparaître une boîte colorée à l'écran, donc supposons que tous les autres codes opengl inclus dans le fonctionnement des fonctions correctement. Voici pourquoi je suis la mise en place mes propriétés de texture:

MAIN.CPP

int main(int agrc, char** argv) 
{ 
    window.Initialize(); 
    playerSprite.Init(-1.0f, -1.0f, 1.0f, 1.0f); 

    GameState gamestate{ GameState::PLAY }; 

    SDL_Event evnt; 

    int32 x, y, currentChannels; 
    int32 forceChannels = 4; 
    uchar8* imageData = 0; 
    imageData = stbi_load("CharImage.png", &x, &y, &currentChannels, forceChannels); 

    if (imageData == nullptr) 
    { 
     LOG("ERROR: Could not load image file!"); 
    }; 

    Blz::OpenGL::ShaderProgram colorShaderProgram; 
    colorShaderProgram.Compile(); 
    colorShaderProgram.Link(); 
    colorShaderProgram.Bind(); 

    GLuint texture; 
    glGenTextures(1, &texture); 
    glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_2D, texture); 

    GLuint uniformLocation = glGetUniformLocation(colorShaderProgram.programID, "basicTexture"); 
    glUniform1i(uniformLocation, 0); 

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); 
    glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

    //Where I am logging to the openGL file 
    Blz::OpenGL::LogShaderProgramProperties(colorShaderProgram.programID); 

    while (gamestate != GameState::EXIT) 
    { 
     unsigned int startTime = SDL_GetTicks(); 

     //Game Logic Update 
     while (SDL_PollEvent(&evnt)) 
     { 
      switch (evnt.type) 
      { 
      case SDL_QUIT: 
       gamestate = GameState::EXIT; 

      default: 
       break; 
      } 
     } 

     window.ClearBuffers(); 

     playerSprite.Draw(); 

     window.SwapBuffers(); 
    } 

    return 0; 
} 

Voici les shaders que je utilise à la variable uniforme de configuration:

Veretx Shader

#version 430 

layout(location=0) in vec3 vertexPosition; 
layout(location=1) in vec2 textCoord; 

out vec2 TextureCoord; 

void main() 
{ 
    gl_Position = vec4(vertexPosition, 1.0f); 
    TextureCoord = textCoord; 
}; 

Fragment Shader

#version 430 

out vec4 daColor; 
in vec2 TextureCoord; 

uniform sampler2D basicTexture; 

void main() 
{ 
    vec4 texel = texture(basicTexture, TextureCoord); 
    daColor = texel; 
}; 

À partir du code ci-dessus, y a-t-il des problèmes qui provoquent l'impression de -1 de mon emplacement de variable uniforme dans le fichier journal?

EDIT:

Voici le code utilisé pour imprimer les informations du journal:

void LogShaderProgramProperties(GLuint shaderProgramID) 
     { 
      //Header 
      OpenGL::LogToFile("-------------------------------------------------\n"); 
      OpenGL::LogToFile("Shader program %i\n", shaderProgramID); 
      OpenGL::LogToFile("-------------------------------------------------\n\n"); 

      int32 result = -1; 
      glGetProgramiv(shaderProgramID, GL_LINK_STATUS, &result); 
      OpenGL::LogToFile("GL_LINK_STATUS = %s\n", (result == GL_TRUE) ? "SUCCESS" : "FAILURE"); 

      glGetProgramiv(shaderProgramID, GL_ATTACHED_SHADERS, &result); 
      OpenGL::LogToFile("GL_ATTACHED_SHADERS = %i\n", result); 

      glGetProgramiv(shaderProgramID, GL_ACTIVE_ATTRIBUTES, &result); 
      OpenGL::LogToFile("GL_ACTIVE_ATTRIBUTES = %i\n", result); 

      //Will log all current active attributes for program/shader 
      for (GLuint i = 0; i < (GLuint)result; ++i) 
      { 
       char8 name[64]; 
       int32 maxLength = 64; 
       int32 actualLength = 0; 
       int32 size = 0; 
       GLenum type; 

       glGetActiveAttrib(shaderProgramID, i, maxLength, &actualLength, &size, &type, name); 
       if (size > 1) 
       { 
        //Sometimes an attribute will contain an array of other attributes for which this 
        //loop will catch and print all contained variables 
        for (int j = 0; j < size; j++) 
        { 
         char8 longName[64]; 
         sprintf(longName, "%s[%i]", name, j); 
         int32 location = glGetAttribLocation(shaderProgramID, longName); 
         OpenGL::LogToFile(" - %i) type:%s name:%s location: %i\n", i, GLTypeToString(type), name, location); 
        } 
       } 
       else 
       { 
        //Just print single attribute information 
        int32 location = glGetAttribLocation(shaderProgramID, name); 
        OpenGL::LogToFile(" - %i) type:%s name:%s location %i\n", i, GLTypeToString(type), name, location); 
       } 
      } 

      glGetProgramiv(shaderProgramID, GL_ACTIVE_UNIFORMS, &result); 
      LogToFile("GL_ACTIVE_UNIFORMS = %i\n", result); 

      //Will log all current active attributes for program/shader 
      for (GLuint i = 0; i < (GLuint)result; ++i) 
      { 
       char8 name[64]; 
       int32 maxLength = 64; 
       int32 actualLength = 0; 
       int32 size = 0; 
       GLenum type; 

       glGetActiveUniform(shaderProgramID, i, maxLength, &actualLength, &size, &type, name); 
       if (size > 1) 
       { 
        //In case a uniform contains an array of other variables/uniforms 
        for (int j = 0; j < size; j++) 
        { 
         char8 longName[64]; 
         sprintf(longName, "%s[%i]", name, j); 
         int32 location = glGetUniformLocation(shaderProgramID, longName); 
         OpenGL::LogToFile(" - %i) type:%s name:%s location: %i\n", i, GLTypeToString(type), longName, location); 
        } 
       } 
       else 
       { 
        //Just print single uniform variable 
        int32 location = glGetAttribLocation(shaderProgramID, name); 
        OpenGL::LogToFile(" - %i) type:%s name:%s location %i\n", i, GLTypeToString(type), name, location); 
       } 
      } 

      int32 maxLength = 2048; 
      int32 actualLength = 0; 
      char8 log[2048]; 
      glGetProgramInfoLog(shaderProgramID, maxLength, &actualLength, log); 
      OpenGL::LogToFile("Program info log for GL index %u:\n%s", shaderProgramID, log); 
     } 
+0

Il n'existe pas d'attribut uniforme. Il y a des "attributs" (entrées de vertex shader) et des "uniformes". Une variable ne peut pas être * les deux *. –

+0

En outre, où est le code pour imprimer toutes ces choses? Le code qui détermine que 'basicTexture' a un emplacement de -1? –

+0

Modifier dans un [mcve]. – genpfault

Répondre

1

Vous essayez d'interroger l'uniforme emplacement via glGetAttribLocation, et il est bien sûr aucun attribut avec ce nom :

  else 
      { 
       //Just print single uniform variable 
       int32 location = glGetAttribLocation(shaderProgramID, name); 
       OpenGL::LogToFile(" - %i) type:%s name:%s location %i\n", i, GLTypeToString(type), name, location); 
      } 
     } 

Quel que soit le problème avec votre texture, ce n'est pas l'emplacement uniforme.

+0

Fantastique merci. Cela aidera au moins à affiner mon problème – Jason