Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Opengl.CubeMap, vertec&fragmentshader error.

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2018
    Posts
    4

    Opengl.CubeMap, vertec&fragmentshader error.

    Hey. new to Opengl and i get this error regarding(i believe) my vertexshader.

    Code :
    ERROR: 0:17: 'gl_Position' : undeclared identifier
    ERROR: 0:17: 'assign' :  cannot convert from '4-component vector of highp float' to 'highp float'

    Any input is highly appreciated thnx.

    Heres the vertexshader

    Code glsl:
    #version 330 core
    layout (location = 0) in vec3 position;
     
        out vec3 TexCoords; 
     
     
        uniform mat4 projection;
        uniform mat4 view;
     
     
        void main()
        {
     
     
     
         TexCoords = position; 
        gl_Position = projection * view * vec4(position.xyz, 1.0);
     
        }

    And the FragmentShader

    Code glsl:
        #version 330 core
     
     
        in vec3 TexCoords;
     
     
        out vec4 color;
     
     
        uniform samplerCube skybox;
     
     
        void main()
        {    
     
        color = texture(skybox,TexCoords);
        }
    Last edited by Dark Photon; 06-12-2018 at 07:10 AM.

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2016
    Posts
    8
    From https://www.khronos.org/files/opengl...rence-card.pdf
    "“#version 150” is required in shaders using version 1.50 of the language. #version
    must occur in a shader before anything else other than white space or comments."
    Try checking for that. (I know it's for 3.2; I couldn't find one for 3.3)

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2018
    Posts
    4
    Quote Originally Posted by Nokturnis View Post
    From https://www.khronos.org/files/opengl...rence-card.pdf
    "#version 150 is required in shaders using version 1.50 of the language. #version
    must occur in a shader before anything else other than white space or comments."
    Try checking for that. (I know it's for 3.2; I couldn't find one for 3.3)

    thx for the response. i replaced the versions of the Vertex&fragmentShader to #150 core which gives me the following error," ERROR: 0:2: 'location' : syntax error syntax error"

    in the VertexShader.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2016
    Posts
    8
    Keep #version 330. Make sure there are no white spaces or comments BEFORE that.

  5. #5
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    881
    Make sure you are compiling your vertex shader source as GL_VERTEX_SHADER, not GL_FRAGMENT_SHADER.

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2018
    Posts
    4
    Quote Originally Posted by arekkusu View Post
    Make sure you are compiling your vertex shader source as GL_VERTEX_SHADER, not GL_FRAGMENT_SHADER.

    Thx for the input. I'm not super-familliar with shaders, however i don't think there's anything wrong with it,then again i really wish to crack this issue.

    Code cpp:
    #include <stdio.h>
    #include <string>
    #include <vector>
    #include <iostream>
    #include <fstream>
    #include <algorithm>
    #include <sstream>
    using namespace std;
     
    #include <stdlib.h>
    #include <string.h>
     
    #include <GL/glew.h>
     
    #include "shader.hpp"
     
     
     
     
     
     
     
     
     
    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::stringstream sstr;
            sstr << VertexShaderStream.rdbuf();
            VertexShaderCode = sstr.str();
            VertexShaderStream.close();
        }else{
            printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
            getchar();
            return 0;
        }
     
        // 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::stringstream sstr;
            sstr << FragmentShaderStream.rdbuf();
            FragmentShaderCode = sstr.str();
            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);
        if ( InfoLogLength > 0 ){
            std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
            glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
            printf("%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);
        if ( InfoLogLength > 0 ){
            std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
            glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
            printf("%s\n", &FragmentShaderErrorMessage[0]);
        }
     
     
     
        // Link the program
        printf("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);
        if ( InfoLogLength > 0 ){
            std::vector<char> ProgramErrorMessage(InfoLogLength+1);
            glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
            printf("%s\n", &ProgramErrorMessage[0]);
        }
     
     
        glDetachShader(ProgramID, VertexShaderID);
        glDetachShader(ProgramID, FragmentShaderID);
     
        glDeleteShader(VertexShaderID);
        glDeleteShader(FragmentShaderID);
     
        return ProgramID;
    }
    Last edited by Dark Photon; 06-12-2018 at 07:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •