Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Created June 17, 2013 12:27
Show Gist options
  • Save pjc0247/5796509 to your computer and use it in GitHub Desktop.
Save pjc0247/5796509 to your computer and use it in GitHub Desktop.
simple glsl test
char* filetobuf(char *file)
{
FILE *fptr;
long length;
char *buf;
fptr = fopen(file, "rb"); /* Open file for reading */
if (!fptr) /* Return NULL on failure */
return NULL;
fseek(fptr, 0, SEEK_END); /* Seek to the end of the file */
length = ftell(fptr); /* Find out how many bytes into the file we are */
buf = (char*)malloc(length+1); /* Allocate a buffer for the entire length of the file and a null terminator */
fseek(fptr, 0, SEEK_SET); /* Go back to the beginning of the file */
fread(buf, length, 1, fptr); /* Read the contents of the file in to the buffer */
fclose(fptr); /* Close the file */
buf[length] = 0; /* Null terminator */
return buf; /* Return the buffer */
}
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)
SDL_GL_GetProcAddress("glCreateProgramObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)
SDL_GL_GetProcAddress("glDeleteObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)
SDL_GL_GetProcAddress("glCreateShaderObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)
SDL_GL_GetProcAddress("glShaderSourceARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)
SDL_GL_GetProcAddress("glCompileShaderARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)
SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)
SDL_GL_GetProcAddress("glAttachObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)
SDL_GL_GetProcAddress("glGetInfoLogARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)
SDL_GL_GetProcAddress("glLinkProgramARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
SDL_GL_GetProcAddress("glUseProgramObjectARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)
SDL_GL_GetProcAddress("glGetUniformLocationARB");
glUniform1fARB = (PFNGLUNIFORM1FARBPROC)
SDL_GL_GetProcAddress("glUniform1fARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)
SDL_GL_GetProcAddress("glUniform1iARB");
GLenum shader_vert = 0;
GLenum shader_frag = 0;
GLenum shader_prog = 0;
char *shader_frag_source;
char *shader_vert_source;
shader_frag_source = filetobuf("frag.frag");
shader_vert_source = filetobuf("vert.vert");
shader_prog = glCreateProgramObjectARB();
shader_vert = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
shader_frag = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
int len = 0;
len = strlen(shader_vert_source);
glShaderSourceARB(shader_vert, 1, (const GLcharARB**)&shader_vert_source, &len);
len = strlen(shader_frag_source);
glShaderSourceARB(shader_frag, 1, (const GLcharARB**)&shader_frag_source, &len);
glCompileShaderARB(shader_vert);
glCompileShaderARB(shader_frag);
glAttachObjectARB(shader_prog, shader_vert);
glAttachObjectARB(shader_prog, shader_frag);
glLinkProgramARB(shader_prog);
glUseProgramObjectARB(shader_prog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment