Results 1 to 3 of 3

Thread: help setting up basic shader

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Location
    AK
    Posts
    17

    help setting up basic shader

    I am trying to experiment using basic shaders in my program, I came across this nice tutorial tutorial by Durian Software that talks you through writing a basic shader "util class" i guess you would call it? So I linked glew to my project and inserted the following into a header file
    Code :
    #include "include\gl\glew.h"
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
     
    static struct {
        /* ... fields for buffer and texture objects */
        GLuint vertex_shader, fragment_shader, program;
     
        struct {
            GLint fade_factor;
            GLint textures[2];
        } uniforms;
     
        struct {
            GLint position;
        } attributes;
     
        GLfloat fade_factor;
    } g_resources;
     
    static GLuint make_shader(GLenum type, const char *filename)
    {
        GLint length;
        char *source = file_content(filename, &amp;length);
        GLuint shader;
        GLint shader_ok;
     
        if (!source)
            return 0;
    	shader = glCreateShader(type);
        glShaderSource(shader, 1, (const GLchar**)&amp;source, &amp;length);
        free(source);
        glCompileShader(shader);
    	glGetShaderiv(shader, GL_COMPILE_STATUS, &amp;shader_ok);
        if (!shader_ok) {
            fprintf(stderr, "Failed to compile %s:\n", filename);
            show_info_log(shader, glGetShaderiv, glGetShaderInfoLog);
            glDeleteShader(shader);
            return 0;
        }
        return shader;
    }
     
    static void show_info_log(
        GLuint object,
        PFNGLGETSHADERIVPROC glGet__iv,
        PFNGLGETSHADERINFOLOGPROC glGet__InfoLog)
    {
        GLint log_length;
        char *log;
     
        glGet__iv(object, GL_INFO_LOG_LENGTH, &amp;log_length);
        log = malloc(log_length);
        glGet__InfoLog(object, log_length, NULL, log);
        fprintf(stderr, "%s", log);
        free(log);
    }
     
    static GLuint make_program(GLuint vertex_shader, GLuint fragment_shader)
    {
        GLint program_ok;
     
        GLuint program = glCreateProgram();
        glAttachShader(program, vertex_shader);
        glAttachShader(program, fragment_shader);
        glLinkProgram(program);
    	 glGetProgramiv(program, GL_LINK_STATUS, &amp;program_ok);
        if (!program_ok) {
            fprintf(stderr, "Failed to link shader program:\n");
            show_info_log(program, glGetProgramiv, glGetProgramInfoLog);
            glDeleteProgram(program);
            return 0;
        }
        return program;
    }
     
    static int make_resources(void)
    {
        /* make buffers and textures ... */
        g_resources.vertex_shader = make_shader(
            GL_VERTEX_SHADER,
            "hello-gl.v.glsl"
        );
        if (g_resources.vertex_shader == 0)
            return 0;
     
        g_resources.fragment_shader = make_shader(
            GL_FRAGMENT_SHADER,
            "hello-gl.f.glsl"
        );
        if (g_resources.fragment_shader == 0)
            return 0;
     
        g_resources.program = make_program(
            g_resources.vertex_shader,
            g_resources.fragment_shader
        );
        if (g_resources.program == 0)
            return 0;
    	g_resources.uniforms.fade_factor
            = glGetUniformLocation(g_resources.program, "fade_factor");
        g_resources.uniforms.textures[0]
            = glGetUniformLocation(g_resources.program, "textures[0]");
        g_resources.uniforms.textures[1]
            = glGetUniformLocation(g_resources.program, "textures[1]");
     
        g_resources.attributes.position
            = glGetAttribLocation(g_resources.program, "position");
     
        return 1;
    }

    But my compiler complains about the following:
    Code :
     
    	9	IntelliSense: "GLchar" is not a type name	
     
    	11	IntelliSense: a value of type "void *" cannot be assigned to an entity of type "char *"	
     
    	7	IntelliSense: identifier "file_contents" is undefined	
     
    	5	IntelliSense: identifier "GLchar" is undefined

    Am I missing something? I searched the internet and it seems like GLchar and the file_contents function do exist?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: help setting up basic shader

    It does not look like you are linking the OpenGl headers, eg gl3.h, gl3ext.h, wgl.h, etc.
    I don't use c or c++, so I can directly tell you which file(s) you need or where to get the latest.
    There are references to these headers here:

    http://www.opengl.org/registry/#headers

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    CA
    Posts
    408

    Re: help setting up basic shader

    If you look inside glew.h with your handy favorite text editor you will see that it typedef's GLchar. Your header is probably not being found since you are using quotes instead of angle brackets. Try replacing your include with

    Code :
    #include <GL/glew.h>

    ANSI C/C++ does not officially support "\" so please use "/" -- it will work in windows if that is your platform. C is used across multiple OSes so sticking to the convention will help in the long run.

Similar Threads

  1. Setting Up a Tessillation Shader
    By GingerBread in forum OpenGL: Linux
    Replies: 2
    Last Post: 03-19-2012, 01:17 PM
  2. Setting Up a Tessillation Shader
    By GingerBread in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-16-2012, 11:53 AM
  3. Basic Vertex Shader / Fragment Shader interaction
    By endlosschleife in forum OpenGL: GLSL
    Replies: 2
    Last Post: 04-19-2011, 05:53 AM
  4. shader model setting?
    By kewuwsi in forum OpenGL: GLSL
    Replies: 7
    Last Post: 03-21-2008, 04:00 PM
  5. Setting Pixel Shader Constant with nv parse
    By melchizedek in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-13-2002, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean