discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help to compile an opengl shader


From: Thomas Gamper
Subject: Re: Help to compile an opengl shader
Date: Wed, 10 Sep 2014 10:00:57 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Am 09.09.2014 23:51, schrieb Germán Arias:
Hi all

I'm newbie with OpenGL, so I'm trying to make a simple app to draw the famous triangle, 
using shaders and the "modern" opengl (not using glBegin, glEnd, glOrtho, ...). 
But I'm unable to compile a simple shader. The related code is:

- (BOOL) compileShader: (GLuint *)shader
                  type: (GLenum)type
                  file: (NSString *)file
{
     GLint status;
     const GLchar *source;
     int InfoLogLength = 0;
source =
       (GLchar *)[[NSString stringWithContentsOfFile: file
                                            encoding: NSUTF8StringEncoding
                                              error: NULL] UTF8String];
     if (!source)
     {
         NSLog(@"Failed to load vertex shader");
         return NO;
     }
*shader = glCreateShader(type);
     glShaderSource(*shader, 1, &source, NULL);
     glCompileShader(*shader);
if (status == GL_TRUE)
       return YES;
     else
       return NO;
}

The shader files (I copied these from internet):

#version 330 core

// Ouput data
out vec3 color;

void main()
{

        // Output color = red
        color = vec3(1,0,0);

}

And:

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;

void main(){

     gl_Position.xyz = vertexPosition_modelspace;
     gl_Position.w = 1.0;

}

Any advice? Thanks

Germán


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep
Hi!

First, be wary what OpenGL version your OpenGL context has been created with (2.1, 3.x, 4.x), it has effects on what funtionality, functions and GLSL versions are available. I see you are using GLSL 3.3, sou you need at least a OpenGL 3.3 context.

Fortunately there are now manpages for all OpenGL main versions online, they have been of great helpt to me:
http://www.opengl.org/sdk/docs/man2/
http://www.opengl.org/sdk/docs/man3/
http://www.opengl.org/sdk/docs/man4/

I recommend this tutorial if you want to know about OpenGL shader compilation and associated error logging/handling. It has been written in the wake of OpenGL 2.0, but it still fits, just stick to OpenGL 2.0 parts in the text.
http://www.lighthouse3d.com/tutorials/glsl-tutorial/

Cheers,
TOM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]