PDA

View Full Version : Pre-mature EOF in Shader???



glfreak
11-10-2008, 09:29 AM
Try this code please, and see if it works for you. I just get the pre-mature EOF compilation error in fragment shader.



void LoadShaders()
{
const GLchar *shaderSrc1[] =
{
"varying vec3 fragNormal;",
"varying vec3 lightDir;",

"attribute vec3 tangent;",
"attribute vec3 normal;",

"uniform vec3 lightSrc;",

"void main()",
"{",
"mat3 tbn;",
"tbn[0] = normalize(tangent);",
"tbn[2] = normalize(normal);",
"tbn[1] = normalize(cross(tangent, tbn[2]));",

"vec3 lv = lightSrc - vec3(gl_Vertex);",

"fragNormal = gl_Normal;",
"lightDir = tbn * lv;",

"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;",
"}"
};

const GLchar *shaderSrc2[] =
{
"varying vec3 fragNormal;",
"varying vec3 lightDir;",

"uniform sampler2D baseTexSamp;",
"uniform sampler2D bumpTexSamp;",

"void main()",
"{",
" float f = dot(normalize(lightDir), normalize(fragNormal));",

" gl_FragColor = texture2D(baseTexSamp, gl_TexCoord[0].st);",

"}"
};

GLuint shader1, shader2;
shader1 = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader1, 10, shaderSrc1, NULL);
glCompileShader(shader1);
int succeeded;
int len;
char info[512];
glGetShaderiv(shader1, GL_COMPILE_STATUS, &succeeded);
if(!succeeded)
{
glGetShaderiv(shader1, GL_INFO_LOG_LENGTH, &len);
glGetShaderInfoLog(shader1, len, &len, info);
printf("\n*** GLSL compilation problem in vertex shader:");
printf("\n*** %s", info);
}
else
{
shader2 = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader2, 10, shaderSrc2, NULL);
glCompileShader(shader2);
glGetShaderiv(shader2, GL_COMPILE_STATUS, &succeeded);
if(!succeeded)
{
glGetShaderiv(shader2, GL_INFO_LOG_LENGTH, &len);
glGetShaderInfoLog(shader1, len, &len, info);
printf("\n*** GLSL compilation problem in fragment shader:");
printf("\n*** %s", info);
}
}
if (succeeded)
{
GLuint program = glCreateProgram();
glAttachShader(program, shader1);
glAttachShader(program, shader2);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &succeeded);
if(!succeeded)
{
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len );
glGetProgramInfoLog(program, len, &len, info);
printf("\n*** GLSL linking problem:");
printf("\n*** %s", info);
}
}

}

glfreak
11-10-2008, 09:46 AM
sorry, this worked!



#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <GL/GLee.h>
#include <GL/glut.h>
#include <GL/glu.h>

#define ARRAY_LEN(a) (sizeof(a)/sizeof(a[0]))

void init(void);
void tini(void);
void display(void);
void reshape(int width, int height);
void idle(void);

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(540, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow("Demo1");

init();

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);

glutMainLoop();

tini();

return 0;
}

void LoadShaders()
{
const GLchar *shaderSrc1[] =
{
"varying vec3 fragNormal;",
"varying vec3 lightDir;",

"attribute vec3 tangent;",
"attribute vec3 normal;",

"uniform vec3 lightSrc;",

"void main()",
"{",
"mat3 tbn;",
"tbn[0] = normalize(tangent);",
"tbn[2] = normalize(normal);",
"tbn[1] = normalize(cross(tangent, tbn[2]));",

"vec3 lv = lightSrc - vec3(gl_Vertex);",

"fragNormal = gl_Normal;",
"lightDir = tbn * lv;",

"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;",
"}"
};

const GLchar *shaderSrc2[] =
{
"varying vec3 fragNormal;",
"varying vec3 lightDir;",

"uniform sampler2D baseTexSamp;",
"uniform sampler2D bumpTexSamp;",

"void main()",
"{",
" float f = dot(normalize(lightDir), normalize(fragNormal));",

" gl_FragColor = texture2D(baseTexSamp, gl_TexCoord[0].st);",

"}"
};

GLuint shader1, shader2;
shader1 = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader1, ARRAY_LEN(shaderSrc1), shaderSrc1, NULL);
glCompileShader(shader1);
int succeeded;
int len;
char info[512];
glGetShaderiv(shader1, GL_COMPILE_STATUS, &amp;succeeded);
if(!succeeded)
{
glGetShaderiv(shader1, GL_INFO_LOG_LENGTH, &amp;len);
glGetShaderInfoLog(shader1, len, &amp;len, info);
printf("\n*** GLSL compilation problem in vertex shader:");
printf("\n*** %s", info);
}
else
{
shader2 = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader2, ARRAY_LEN(shaderSrc2), shaderSrc2, NULL);
glCompileShader(shader2);
glGetShaderiv(shader2, GL_COMPILE_STATUS, &amp;succeeded);
if(!succeeded)
{
glGetShaderiv(shader2, GL_INFO_LOG_LENGTH, &amp;len);
glGetShaderInfoLog(shader2, len, &amp;len, info);
printf("\n*** GLSL compilation problem in fragment shader:");
printf("\n*** %s", info);
}
}
if (succeeded)
{
GLuint program = glCreateProgram();
glAttachShader(program, shader1);
glAttachShader(program, shader2);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &amp;succeeded);
if(!succeeded)
{
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &amp;len );
glGetProgramInfoLog(program, len, &amp;len, info);
printf("\n*** GLSL linking problem:");
printf("\n*** %s", info);
}
}

}

void init(void)
{
LoadShaders();

glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);

glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);


}

void tini()
{

}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


}

void reshape(int width, int height)
{

}

void idle(void)
{
glutPostRedisplay();
}




Sorry ATI, it's the C# .NET stinky testicles.

glfreak
11-10-2008, 11:06 AM
The problem fixed, yeah it was C# way of handling strings.

IneQuation.pl
11-10-2008, 12:39 PM
I told you I dislike .NET. :D