Herramientas de usuario

Herramientas del sitio


fw:ogl:ogl4

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
fw:ogl:ogl4 [2013/03/04 22:17]
alfred [Entorno]
fw:ogl:ogl4 [2020/05/09 09:25] (actual)
Línea 5: Línea 5:
 <code cpp> <code cpp>
 #define GL_GLEXT_PROTOTYPES 1 #define GL_GLEXT_PROTOTYPES 1
-# include ​ <​GL/​gl.h>​ +#​include ​ <​GL/​gl.h>​ 
-# include ​ <​GL/​glext.h>​+#​include ​ <​GL/​glext.h>​
 </​code>​ </​code>​
-===== Shaders ===== 
  
 +===== Almacenaje de datos =====
 +==== Arrays ====
 +=== Arrays indexados ===
 +==== Buffers ====
 +
 +
 +
 +
 +===== Shaders =====
 +==== Creación de un programa de shaders ====
 +<code cpp>
 +GLuint LoadShaders(const char * vertex_file_path,​const char * fragment_file_path){
 + 
 +     // Create the shaders
 +    GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);​
 +    GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);​
 + 
 +    // Read the Vertex Shader code from the file
 +    std::string VertexShaderCode;​
 +    std::​ifstream VertexShaderStream(vertex_file_path,​ std::​ios::​in);​
 +    if(VertexShaderStream.is_open())
 +    {
 +        std::string Line = "";​
 +        while(getline(VertexShaderStream,​ Line))
 +            VertexShaderCode += "​\n"​ + Line;
 +        VertexShaderStream.close();​
 +    }
 + 
 +    // Read the Fragment Shader code from the file
 +    std::string FragmentShaderCode;​
 +    std::​ifstream FragmentShaderStream(fragment_file_path,​ std::​ios::​in);​
 +    if(FragmentShaderStream.is_open()){
 +        std::string Line = "";​
 +        while(getline(FragmentShaderStream,​ Line))
 +            FragmentShaderCode += "​\n"​ + Line;
 +        FragmentShaderStream.close();​
 +    }
 + 
 +    GLint Result = GL_FALSE;
 +    int InfoLogLength;​
 + 
 +    // Compile Vertex Shader
 +    printf("​Compiling shader : %s\n", vertex_file_path);​
 +    char const * VertexSourcePointer = VertexShaderCode.c_str();​
 +    glShaderSource(VertexShaderID,​ 1, &​VertexSourcePointer , NULL);
 +    glCompileShader(VertexShaderID);​
 + 
 +    // Check Vertex Shader
 +    glGetShaderiv(VertexShaderID,​ GL_COMPILE_STATUS,​ &​Result);​
 +    glGetShaderiv(VertexShaderID,​ GL_INFO_LOG_LENGTH,​ &​InfoLogLength);​
 +    std::​vector<​char>​ VertexShaderErrorMessage(InfoLogLength);​
 +    glGetShaderInfoLog(VertexShaderID,​ InfoLogLength,​ NULL, &​VertexShaderErrorMessage[0]);​
 +    fprintf(stdout,​ "​%s\n",​ &​VertexShaderErrorMessage[0]);​
 + 
 +    // Compile Fragment Shader
 +    printf("​Compiling shader : %s\n", fragment_file_path);​
 +    char const * FragmentSourcePointer = FragmentShaderCode.c_str();​
 +    glShaderSource(FragmentShaderID,​ 1, &​FragmentSourcePointer , NULL);
 +    glCompileShader(FragmentShaderID);​
 + 
 +    // Check Fragment Shader
 +    glGetShaderiv(FragmentShaderID,​ GL_COMPILE_STATUS,​ &​Result);​
 +    glGetShaderiv(FragmentShaderID,​ GL_INFO_LOG_LENGTH,​ &​InfoLogLength);​
 +    std::​vector<​char>​ FragmentShaderErrorMessage(InfoLogLength);​
 +    glGetShaderInfoLog(FragmentShaderID,​ InfoLogLength,​ NULL, &​FragmentShaderErrorMessage[0]);​
 +    fprintf(stdout,​ "​%s\n",​ &​FragmentShaderErrorMessage[0]);​
 + 
 +    // Link the program
 +    fprintf(stdout,​ "​Linking program\n"​);​
 +    GLuint ProgramID = glCreateProgram();​
 +    glAttachShader(ProgramID,​ VertexShaderID);​
 +    glAttachShader(ProgramID,​ FragmentShaderID);​
 +    glLinkProgram(ProgramID);​
 + 
 +    // Check the program
 +    glGetProgramiv(ProgramID,​ GL_LINK_STATUS,​ &​Result);​
 +    glGetProgramiv(ProgramID,​ GL_INFO_LOG_LENGTH,​ &​InfoLogLength);​
 +    std::​vector<​char>​ ProgramErrorMessage( max(InfoLogLength,​ int(1)) );
 +    glGetProgramInfoLog(ProgramID,​ InfoLogLength,​ NULL, &​ProgramErrorMessage[0]);​
 +    fprintf(stdout,​ "​%s\n",​ &​ProgramErrorMessage[0]);​
 + 
 +    glDeleteShader(VertexShaderID);​
 +    glDeleteShader(FragmentShaderID);​
 + 
 +    return ProgramID;
 +}
 +</​code>​
fw/ogl/ogl4.1362435438.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)