Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN SOURCE
- #include <SDL.h>
- #include <GL/glew.h>
- #include <SDL_opengl.h>
- #include <stdio.h>
- #include <conio.h>
- #define SCREEN_HEIGHT 480
- #define SCREEN_WIDTH 640
- SDL_Renderer *mainrenderer;
- SDL_Window *mainwindow;
- SDL_Event event;
- bool running = true;
- const char *GetStringFromFile(const char *stringfilename)
- {
- FILE *file;
- errno_t err;
- err = fopen_s(&file, stringfilename, "ab"); // open the file at the end and binary
- if (err != 0 )
- {
- printf("can't be opened");
- }
- long length = ftell(file);// Ask the size of the file
- printf("file length is %ld \n", length);
- fseek(file, 0, SEEK_SET); // return to the beginning of the file
- char *buffer = calloc(length + 1, sizeof(char)); // alloc the buffer with the end 0
- fread(buffer, sizeof(char), length, file); // read the file
- fclose(file);
- printf(buffer);
- //FILE *stringfile = fopen_s(&stringfile, stringfilename, "ab"); // open the file at the end and binary
- //int length = ftell(stringfile); // Ask the size of the file
- //fseek(stringfile, 0, SEEK_SET); // return to the beginning of the file
- //char *buffer = calloc(length + 1, sizeof(char)); // alloc the buffer with the end 0
- //fread(buffer, sizeof(char), length, stringfile); // read the file
- //fclose(stringfile);
- //return buffer;
- //printf(buffer);
- //return buffer;
- };
- GLuint LoadShaders(const char *fragshaderfn, const char *vertshaderfn, GLuint vertshader, GLuint fragshader)
- {
- const char * vertfilesource = GetStringFromFile(vertshaderfn);
- int vertlenofstr = strlen(vertfilesource);
- printf("\n\n\n\n this is the length -> %d", vertlenofstr);
- glShaderSource(vertshader, 1,
- &vertfilesource, &vertlenofstr);
- glCompileShader(vertshader);
- const char *vertshaderinfolog[256] = { 0 };
- int vertlenofils = strlen(vertshaderinfolog);
- glGetShaderInfoLog(vertshader, sizeof(char) * 256, vertlenofils, vertshaderinfolog);
- printf(vertshaderinfolog);
- GLuint vertprogram = glCreateProgram();
- glAttachShader(vertprogram, vertshader);
- glLinkProgram(vertprogram);
- const char *vertproginfolog[256] = { 0 };
- int vertlenoffp = strlen(vertproginfolog);
- glGetProgramInfoLog(vertprogram, sizeof(char) * 256, vertlenoffp, vertproginfolog);
- printf(vertproginfolog);
- glUseProgram(vertprogram);
- const char * fragfilesource = GetStringFromFile(fragshaderfn);
- int fraglenofstr = strlen(fragfilesource);
- printf("\n\n\n\n this is the length -> %d", fraglenofstr);
- glShaderSource(fragshader,1,
- &fragfilesource, &fraglenofstr);
- glCompileShader(fragshader);
- const char *fragshaderinfolog[256] = { 0 };
- int fraglenofils = strlen(fragshaderinfolog);
- glGetShaderInfoLog(fragshader, sizeof(char) * 256, fraglenofils, fragshaderinfolog);
- printf("\n\n\n\n FRAG SHADER INFO LOG", fragshaderinfolog);
- GLuint fragprogram = glCreateProgram();
- glAttachShader(fragprogram, fragshader);
- glLinkProgram(fragprogram);
- const char *fragproginfolog[256] = { 0 };
- int fraglenoffp = strlen(fragproginfolog);
- glGetProgramInfoLog(fragprogram, sizeof(char) * 256, fraglenoffp, fragproginfolog);
- printf("\n\n\n\n FRAG PROG INFO LOG",fragproginfolog);
- glUseProgram(fragprogram);
- return fragshader;
- return vertshader;
- };
- int main(int argc , char **argv)
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- mainwindow = SDL_CreateWindow(
- "C OpenGL Engine",
- 300, 300, 640, 480,
- SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL );
- SDL_GLContext maincontext = SDL_GL_CreateContext(mainwindow);
- SDL_GL_MakeCurrent(mainwindow, maincontext);
- glewExperimental = GL_TRUE;
- GLenum err = glewInit();
- GLuint vertshaderhandle = glCreateShader(GL_VERTEX_SHADER),
- fragshaderhandle = glCreateShader(GL_FRAGMENT_SHADER);
- if (GLEW_OK != err)
- {
- /* Problem: glewInit failed, something is seriously wrong. */
- fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
- }
- printf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
- if (SDL_GL_SetSwapInterval(1) < 0)
- {
- printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError());
- }
- //LoadShaders("cunt.frag", "cunter.vert", vertshaderhandle, fragshaderhandle);
- GetStringFromFile("cunt.frag");
- glClearColor(0.0, 0.0, 0.0, 1.0);
- GLuint projmat = glGetUniformLocation(vertshaderhandle, "projection");
- //printf("\n\n\n\n\n\n\n Projmat : %d",projmat);
- while (running == true)
- {
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- SDL_GL_DeleteContext(maincontext);
- SDL_Quit();
- return 0;
- break;
- }
- }
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- SDL_GL_SwapWindow(mainwindow);
- }
- SDL_GL_DeleteContext(maincontext);
- SDL_DestroyWindow(mainwindow);
- SDL_Quit();
- return 0;
- }
- /*int errorflag = glGetError();
- if (errorflag == GL_NO_ERROR)
- {
- printf("something happend maybe?");
- }*/
- /*char fragfilecontents[500] = { 0 };
- char fragshadercompilelogcontents[500] = { 0 };
- char fragshaderlength[500] = { 0 };
- char fragshadercompilestatus[500] = { 0 };
- while ((fragfilecontents[0] = fgetc(fragfile)) != EOF)
- {
- printf(fragfilecontents);
- }
- GLuint fragshader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragshader, 0,
- (const GLchar **)&fragfilecontents, NULL);*/
- //glCompileShader(fragshader);
- //GLint compile_status;
- //glGetShaderiv(fragshader, GL_COMPILE_STATUS, &fragshadercompilestatus);
- //printf("%s",fragshadercompilestatus);
- // glGetShaderiv(fragshader, GL_INFO_LOG_LENGTH, &fragshaderlength);
- //glGetShaderInfoLog(fragshader, 256, &fragshaderlength, fragshadercompilelogcontents[0]);
- //printf("%s",fragshaderlength[0]);
- //PROPER READ AND WRITE :
- //const char *getStringFromFile(char const *path) {
- // FILE *file = fopen(path, "ab"); // open the file at the end and binary
- // int length = ftell(file); // Ask the size of the file
- // fseek(file, 0, SEEK_SET); // return to the beginning of the file
- // char *buffer = calloc(length + 1, sizeof(char)); // alloc the buffer with the end 0
- // fread(buffer, sizeof(char), length, file); // read the file
- // fclose(file);
- // return buffer;
- //}
- //CUNT.FRAG
- #version 330
- out vec4 color;
- void main()
- {
- color = vec4(1.0, 0.0, 0.0, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement