#define GLEW_STATIC #define NO_SDL_GLEXT #include <GL/glew.h> #include <SDL2/SDL.h> #include <SDL2/SDL_opengl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFSIZE 1024 #define MAXSIZE 1048576 typedef struct Shader { unsigned int data; } Shader; char* loadshader(char*); Shader* createShader(char* vertexfile, char* fragmentfile) { char msg[512]; char log[512]; int success; const char* vertexcode = loadshader(vertexfile); unsigned int vertex = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertex, 1, &vertexcode, NULL); glCompileShader(vertex); { char log[512]; int success; glGetProgramiv(vertex, GL_LINK_STATUSGL_COMPILE_STATUS, &success); if (!success) { printf("Vertex File Name: %s\n", vertexfile); printf("Vertex Code: %d\n", vertexcode); printf("Vertex Value: %d\n", vertex); glGetProgramInfoLog(vertex, 512, NULL, log); printf(strcat(strcpy(msg, "Vertex Shader Failed to Compile!\n> OpenGL Error: "),%s\n\n log)); - - - - }- \n\n", log); } const char* fragmentcode = loadshader(fragmentfile); unsigned int fragment = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment, 1, &fragmentcode, NULL); glCompileShader(fragment); { char log[512]; int success; glGetProgramiv(fragment, GL_LINK_STATUSGL_COMPILE_STATUS, &success); if (!success) { printf("\n\nFragment"Fragment File Name: %s\n", fragmentfile); printf("Fragment Code: %d\n", fragmentcode); printf("Fragment Value: %d\n", fragment); glGetProgramInfoLog(fragment, 512, NULL, log); printf(strcat(strcpy(msg, "Fragment Shader Failed to LinkCompile!\n> OpenGL Error"),Error: log)); %s\n\n - - - }- - \n\n", log); } unsigned int data = glCreateProgram(); glAttachShader(data, vertex); glAttachShader(data, fragment); glLinkProgram(data); { char log[512]; int success; glGetProgramiv(data, GL_LINK_STATUS, &success); if (!success) { printf("Program Value: %d\n", data); glGetProgramInfoLog(data, 512, NULL, log); printf(strcat(strcpy(msg, "\n\nShader Program"Shader Failed to Link!\n> OpenGL Error: ")%s", log)); } } glDeleteShader(vertex); glDeleteShader(fragment); free((void*) vertexcode); free((void*) fragmentcode); Shader* shader = (Shader*) malloc(sizeof(Shader)); shader -> data = data; return shader; } int mainWinMain(int argc, char const *argv[]) { glewInitSDL_Init(SDL_INIT_VIDEO); Shader*SDL_Window* shaderwindow = createShaderSDL_CreateWindow("data/test.vs""Basic Window", "data/test.fs"660, 240, 600, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); printf("%s\n",SDL_GLContext shadercontext ?= "ShaderSDL_GL_CreateContext(window); Successfully Created!"glewInit(); : "FailedShader* toshader Create= Shader!"createShader("data/test.vs", "data/test.fs"); return 0; } char* loadshader(char* filename) { FILE* file = fopen(filename, "r"); if (!file) return NULL; int flag = 0; char* shader = (char*) malloc(MAXSIZE); char* buffer = (char*) malloc(BUFFSIZE); while (fgets(buffer, BUFFSIZE, file) != NULL) strcat(shader, buffer); free(buffer); fclose(file); printf("\"%s\" Content:\n%s\n", filename, shader); return shader; }
"data/test.vs" Content: #version 330 core layout (location = 0) in vec3 POSITION; void main() { gl_Position = vec4(POSITION, 1.0); } Vertex File Name: data/test.vs Vertex Code: 81465408-1521078208 Vertex Value: 1 Vertex Shader Failed to Compile! > OpenGL Error: ░☻░╗x¥j☻ - - - - - "data/test.fs" Content: #version 330 core out vec4 COLOR; void main() { COLOR = vec4((1.0f, 0.5f, 0.2f, 1.0f); } Fragment File Name: data/test.fs Fragment Code: 82587712-1486147520 Fragment Value: 2 Fragment Shader Failed to Compile! > OpenGL Error: ░☻░╗x¥j☻ [process exited- with- code- 4294967295- - Program Value: 3 Shader Failed to Link! > OpenGL Error: Fragment shader(0xffffffffs)] were not successfully compiled before glLinkProgram() was called. Link failed.