Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMadd

Posted 31 August 2012 - 03:42 AM

Here's the code for the loader:

[source lang="cpp"]void meEnableShaders(){ /* load the fragment shader */ char *frag_buffer, *vert_buffer; FILE *fp = fopen("MaddEngine.frag", "rb"); int frag_size; fseek(fp, 0, SEEK_END); frag_size = ftell(fp); fseek(fp, 0, SEEK_SET); frag_buffer = (char*)malloc(frag_size); fread(frag_buffer, 1, frag_size, fp); fclose(fp); /* load the vertex shader */ fp = fopen("MaddEngine.vert", "rb"); int vert_size; fseek(fp, 0, SEEK_END); vert_size = ftell(fp); vert_buffer = (char*)malloc(vert_size); fread(vert_buffer, 1, vert_size, fp); fclose(fp);#ifdef ARB_SHADER me_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); glShaderSourceARB(me_fragment_shader, 1, &frag_buffer, &frag_size); glCompileShaderARB(me_fragment_shader); me_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); glShaderSourceARB(me_vertex_shader, 1, &vert_buffer, &vert_size); glCompileShaderARB(me_vertex_shader); me_shader_program = glCreateProgramObjectARB(); glAttachObjectARB(me_shader_program, me_fragment_shader); glAttachObjectARB(me_shader_program, me_vertex_shader); glLinkProgramARB(me_shader_program); glUseProgramObjectARB(me_shader_program);#else me_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(me_fragment_shader, 1, &frag_buffer, &frag_size); glCompileShader(me_fragment_shader); me_vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(me_vertex_shader, 1, &vert_buffer, &vert_size); glCompileShader(me_vertex_shader); me_shader_program = glCreateProgram(); glAttachShader(me_shader_program, me_fragment_shader); glAttachShader(me_shader_program, me_vertex_shader); glLinkProgram(me_shader_program); glUseProgram(me_shader_program);#endif free(frag_buffer); free(vert_buffer);};[/source]


It is compiled without the ARB_SHADER macro (so it uses the standard OpenGL functions).

I edit the files with gedit under Ubuntu, which uses UTF-8.

#1Madd

Posted 31 August 2012 - 03:40 AM

Here's the code for the loader:

[source lang="cpp"]void meEnableShaders(){ /* load the fragment shader */ char *frag_buffer, *vert_buffer; FILE *fp = fopen("MaddEngine.frag", "rb"); int frag_size; fseek(fp, 0, SEEK_END); frag_size = ftell(fp); fseek(fp, 0, SEEK_SET); frag_buffer = (char*)malloc(frag_size); fread(frag_buffer, 1, frag_size, fp); fclose(fp); /* load the vertex shader */ fp = fopen("MaddEngine.vert", "rb"); int vert_size; fseek(fp, 0, SEEK_END); vert_size = ftell(fp); vert_buffer = (char*)malloc(vert_size); fread(vert_buffer, 1, vert_size, fp); fclose(fp);#ifdef ARB_SHADER me_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); glShaderSourceARB(me_fragment_shader, 1, &frag_buffer, &frag_size); glCompileShaderARB(me_fragment_shader); me_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); glShaderSourceARB(me_vertex_shader, 1, &vert_buffer, &vert_size); glCompileShaderARB(me_vertex_shader); me_shader_program = glCreateProgramObjectARB(); glAttachObjectARB(me_shader_program, me_fragment_shader); glAttachObjectARB(me_shader_program, me_vertex_shader); glLinkProgramARB(me_shader_program); glUseProgramObjectARB(me_shader_program);#else me_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(me_fragment_shader, 1, &frag_buffer, &frag_size); glCompileShader(me_fragment_shader); me_vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(me_vertex_shader, 1, &vert_buffer, &vert_size); glCompileShader(me_vertex_shader); me_shader_program = glCreateProgram(); glAttachShader(me_shader_program, me_fragment_shader); glAttachShader(me_shader_program, me_vertex_shader); glLinkProgram(me_shader_program); glUseProgram(me_shader_program);#endif free(frag_buffer);};[/source]


It is compiled without the ARB_SHADER macro (so it uses the standard OpenGL functions).

I edit the files with gedit under Ubuntu, which uses UTF-8.

PARTNERS