From a240df3979e176a5cf3fb4ccd9338695e8d917e3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 2 Feb 2016 06:12:13 +0100 Subject: Fix indentation --- glslview.c | 168 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/glslview.c b/glslview.c index 940c30d..c9d8915 100644 --- a/glslview.c +++ b/glslview.c @@ -23,117 +23,117 @@ static GLint res_loc; static char * readfile(const char *filename) { - FILE *f = fopen(filename, "r"); - if (!f) - return NULL; - - size_t size = 1024; - char *buffer = malloc(size+1); - size_t count = 0, r; - - do { - if (count == size) { - size *= 2; - buffer = realloc(buffer, size+1); - } + FILE *f = fopen(filename, "r"); + if (!f) + return NULL; + + size_t size = 1024; + char *buffer = malloc(size+1); + size_t count = 0, r; + + do { + if (count == size) { + size *= 2; + buffer = realloc(buffer, size+1); + } - r = fread(buffer+count, 1, size-count, f); - count += r; - } while (r); + r = fread(buffer+count, 1, size-count, f); + count += r; + } while (r); - fclose(f); + fclose(f); - buffer[count] = 0; + buffer[count] = 0; - return buffer; + return buffer; } static void printShaderInfoLog(GLuint obj) { - GLint length = 0; + GLint length = 0; - glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &length); + glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &length); - if(length > 0) { - char log[length]; + if(length > 0) { + char log[length]; - glGetShaderInfoLog(obj, sizeof(log), NULL, log); - fprintf(stderr, "%s\n", log); - } + glGetShaderInfoLog(obj, sizeof(log), NULL, log); + fprintf(stderr, "%s\n", log); + } } static void printProgramInfoLog(GLuint obj) { - GLint length = 0; + GLint length = 0; - glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &length); + glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &length); - if(length > 0) { - char log[length]; + if(length > 0) { + char log[length]; - glGetProgramInfoLog(obj, sizeof(log), NULL, log); - fprintf(stderr, "%s\n", log); - } + glGetProgramInfoLog(obj, sizeof(log), NULL, log); + fprintf(stderr, "%s\n", log); + } } static void init(char *filename) { - glewInit(); + glewInit(); glDisable(GL_DEPTH_TEST); - char *shader = readfile(filename); - if (!shader) { - fprintf(stderr, "Error: unable to read '%s'\n", filename); - exit(1); - } + char *shader = readfile(filename); + if (!shader) { + fprintf(stderr, "Error: unable to read '%s'\n", filename); + exit(1); + } - GLuint frag = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(frag, 1, (const GLchar **)&shader, NULL); - glCompileShader(frag); - printShaderInfoLog(frag); + GLuint frag = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(frag, 1, (const GLchar **)&shader, NULL); + glCompileShader(frag); + printShaderInfoLog(frag); - GLuint program = glCreateProgram(); - glAttachShader(program, frag); + GLuint program = glCreateProgram(); + glAttachShader(program, frag); - glLinkProgram(program); - printProgramInfoLog(program); + glLinkProgram(program); + printProgramInfoLog(program); - glBindFragDataLocation(program, 0, "fragColor"); - time_loc = glGetUniformLocation(program, "time"); - res_loc = glGetUniformLocation(program, "res"); + glBindFragDataLocation(program, 0, "fragColor"); + time_loc = glGetUniformLocation(program, "time"); + res_loc = glGetUniformLocation(program, "res"); - glUseProgram(program); + glUseProgram(program); } #ifdef GLSLWRITE static void savePNG(int width, int height, const char *output_dir) { - uint8_t pixels[width*height*4]; - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels); + uint8_t pixels[width*height*4]; + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels); - char filename[strlen(output_dir) + 20]; - snprintf(filename, sizeof(filename), "%s/%010u.png", output_dir, frame_time); + char filename[strlen(output_dir) + 20]; + snprintf(filename, sizeof(filename), "%s/%010u.png", output_dir, frame_time); - FILE *f = fopen(filename, "wb"); + FILE *f = fopen(filename, "wb"); if (!f) { - fprintf(stderr, "unable to open PNG file\n"); - exit(1); - } + fprintf(stderr, "unable to open PNG file\n"); + exit(1); + } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { - fprintf(stderr, "unable to open PNG file\n"); - exit(1); - } + fprintf(stderr, "unable to open PNG file\n"); + exit(1); + } - png_set_swap_alpha(png_ptr); + png_set_swap_alpha(png_ptr); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { fprintf(stderr, "unable to create PNG info struct\n"); - exit(1); + exit(1); } if (setjmp(png_jmpbuf(png_ptr))) { fprintf(stderr, "unable to write PNG file\n"); - exit(1); + exit(1); } png_init_io(png_ptr, f); @@ -157,11 +157,11 @@ static void render(int width, int height) { glViewport(0, 0, (GLsizei)width, (GLsizei)height); #ifdef GLSLWRITE - glUniform1f(time_loc, frame_time); + glUniform1f(time_loc, frame_time); #else - glUniform1f(time_loc, SDL_GetTicks()); + glUniform1f(time_loc, SDL_GetTicks()); #endif - glUniform2f(res_loc, width, height); + glUniform2f(res_loc, width, height); glBegin(GL_QUADS); glVertex2f(-1, -1); @@ -171,7 +171,7 @@ static void render(int width, int height) { glEnd(); #ifdef GLSLWRITE - frame_time += 20; + frame_time += 20; #endif } @@ -180,23 +180,23 @@ int main(int argc, char *argv[]) { bool running = true; #ifdef GLSLWRITE - if (argc != 3) { - fprintf(stderr, "Usage: glslwrite \n"); - exit(1); - } + if (argc != 3) { + fprintf(stderr, "Usage: glslwrite \n"); + exit(1); + } #else - if (argc != 2) { - fprintf(stderr, "Usage: glslview \n"); - exit(1); - } + if (argc != 2) { + fprintf(stderr, "Usage: glslview \n"); + exit(1); + } #endif SDL_Init(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("glslwrite", 0, 0, 800, 800, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); - SDL_GL_CreateContext(window); + SDL_GL_CreateContext(window); - init(argv[1]); + init(argv[1]); while (running) { SDL_Event e; @@ -204,18 +204,18 @@ int main(int argc, char *argv[]) { while( SDL_PollEvent(&e)) { if(e.type == SDL_QUIT) { running = false; - break; + break; } } - int width, height; - SDL_GetWindowSize(window, &width, &height); + int width, height; + SDL_GetWindowSize(window, &width, &height); render(width, height); - SDL_GL_SwapWindow(window); + SDL_GL_SwapWindow(window); #ifdef GLSLWRITE - savePNG(width, height, argv[2]); + savePNG(width, height, argv[2]); #endif } -- cgit v1.2.3