gem-graph-client/include/shaders_study.h

111 lines
2.6 KiB
C

/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "base.h"
#include <unistd.h>
#include <stdbool.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
/*
* Initializes the shaders of a gl_area and link them to a program
*
* @param gl_area, ptr to the gl_area widget
*
* @return true if initialized
*/
bool graphics_init_shaders(const void *gl_area);
/*
* Created and compile a shader
*
* @param type, shader type
* src, source code of shader
*
* @return shader id
*/
static inline GLuint create_shader(int type, const char *src)
{
GLuint shader;
int status;
shader = glCreateShader(type);
glShaderSource(shader, 1, &src, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if(status == GL_FALSE) {
int log_len;
char *buffer;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
buffer = g_malloc(log_len + 1);
assert (buffer);
glGetShaderInfoLog(shader, log_len, NULL, buffer);
g_warning("Compile failure in %s shader:\n%s",
type == GL_VERTEX_SHADER ? "vertex" : "fragment",
buffer);
g_free(buffer);
glDeleteShader(shader);
return 0;
}
return shader;
}
/*
* Find the gl_area_entry size
*
* @param void
*
* @return size of array
*/
// extern struct gl_area_entry **gl_area_array;
// static inline short gl_area_size(void)
// {
// struct gl_area_entry **cur;
// short size;
// Check uninitialized and quit
// if (gl_area_array == NULL) return 0;
// cur = gl_area_array;
// while(*cur) {
// cur++;
// size++;
// }
// return size;
// }
/*** TEST ***/
// void main_test_graphics (void);