FB Graphics
FBGraphics (FBG) : Simple C 16, 24, 32 bpp generic graphics library with parallelism support and custom backend.
fbg_glfw.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2018, Julien Verneuil
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the organization nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL Julien Verneuil BE LIABLE FOR ANY
20  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef FB_GRAPHICS_GLFW_H
29 #define FB_GRAPHICS_GLFW_H
30 
31  #include <GL/glew.h>
32  #include <GLFW/glfw3.h>
33 
34  #include "fbgraphics.h"
35 
39  GLFWwindow *window;
41  GLFWmonitor *monitor;
45  GLuint fbg_vao;
47  GLuint fbg_texture;
50  };
51 
53  extern const GLfloat fbg_glfwQuad[];
54 
56  extern const char *fbg_glfwSimpleVs;
57 
59  extern const char *fbg_glfwSimpleFs;
60 
62 
71  extern struct _fbg *fbg_glfwSetup(int width, int height, int components, const char *title, int monitor, int fullscreen);
72 
74  extern void fbg_glfwClear();
75 
77 
80  extern void fbg_glfwUpdateBuffer(struct _fbg *fbg);
81 
83 
87  extern int fbg_glfwShouldClose(struct _fbg *fbg);
88 
90 
94  extern void fbg_glfwFullscreen(struct _fbg *fbg, int enable);
95 
97 
102  extern void fbg_glfwResize(struct _fbg *fbg, unsigned int new_width, unsigned new_height);
103 
105 
110  GLuint fbg_glfwCreateTextureFromImage(struct _fbg *fbg, struct _fbg_img *img);
111 
112  //-- A SET OF RAW OPENGL UTILITY FUNCTIONS --
114 
120  extern GLuint fbg_glfwCreateTexture(GLuint width, GLuint height, GLint internal_format);
121 
123 
137  extern GLuint fbg_glfwCreateVAO(GLsizeiptr indices_count, const GLvoid *indices_data, size_t sizeof_indice_type,
138  GLsizeiptr vertices_count, const GLvoid *vertices_data,
139  GLsizeiptr texcoords_count, const GLvoid *texcoords_data,
140  GLsizeiptr normals_count, const GLvoid *normals_data,
141  GLsizeiptr colors_count, const GLvoid *colors_data);
142 
144 
149  extern GLuint fbg_glfwCreateVAOvu(GLsizeiptr data_count, const GLvoid *data);
150 
152 
156  extern GLuint fbg_glfwCreateFBO(GLuint texture);
157 
159 
164  extern GLuint fbg_glfwCreateShader(GLenum type, const GLchar *source);
165 
167 
172  extern GLuint fbg_glfwCreateShaderFromFile(GLenum type, const char *filename);
173 
175 
181  extern GLuint fbg_glfwCreateProgram(GLuint vertex_shader, GLuint fragment_shader, GLuint geometry_shader);
182 
184 
190  extern GLenum fbg_glfwCreateProgramFromFiles(const char *vs, const char *fs, const char *gs);
191 
193 
199  extern GLenum fbg_glfwCreateProgramFromString(const char *vs, const char *fs, const char *gs);
200 
201 #endif
GLuint fbg_glfwCreateTextureFromImage(struct _fbg *fbg, struct _fbg_img *img)
create a non-interpolated (NEAREST) GL texture from a FBG image
GLFWmonitor * monitor
GLFW monitor.
Definition: fbg_glfw.h:41
void fbg_glfwResize(struct _fbg *fbg, unsigned int new_width, unsigned new_height)
Display resize.
int components
Display components amount (3 = 24 BPP / 4 = 32 BPP)
Definition: fbgraphics.h:176
GLuint fbg_texture
FBG texture (updated at each frames)
Definition: fbg_glfw.h:47
int update_buffer
tell wether fbg_glfw should update fbg disp_buffer after rendering
Definition: fbg_glfw.h:49
void fbg_glfwUpdateBuffer(struct _fbg *fbg)
this update FBG disp_buffer with the actual rendered OpenGL content
GLuint fbg_glfwCreateVAO(GLsizeiptr indices_count, const GLvoid *indices_data, size_t sizeof_indice_type, GLsizeiptr vertices_count, const GLvoid *vertices_data, GLsizeiptr texcoords_count, const GLvoid *texcoords_data, GLsizeiptr normals_count, const GLvoid *normals_data, GLsizeiptr colors_count, const GLvoid *colors_data)
create a VAO from indexed data, support for vertices, UVs, normals and colors
struct _fbg * fbg_glfwSetup(int width, int height, int components, const char *title, int monitor, int fullscreen)
initialize a FB Graphics OpenGL context (GLFW library)
int width
Display width in pixels.
Definition: fbgraphics.h:170
int new_width
Requested new display width (resize event)
Definition: fbgraphics.h:183
int new_height
Requested new display height (resize event)
Definition: fbgraphics.h:185
GLFW wrapper data structure.
Definition: fbg_glfw.h:37
GLenum fbg_glfwCreateProgramFromString(const char *vs, const char *fs, const char *gs)
create a vertex and/or fragment/geometry program from a string
const char * fbg_glfwSimpleFs
Simple textured fragment shader.
const GLfloat fbg_glfwQuad[]
Simple quad geometry (vertices + UV)
int height
Display height in pixels.
Definition: fbgraphics.h:172
int fbg_glfwShouldClose(struct _fbg *fbg)
Query the user requested (window close etc) close status.
GLenum fbg_glfwCreateProgramFromFiles(const char *vs, const char *fs, const char *gs)
create a vertex and/or fragment/geometry program from a file
const char * fbg_glfwSimpleVs
Simple vertex shader (screen quad, vertices + UV)
GLFWwindow * window
GLFW window.
Definition: fbg_glfw.h:39
GLuint fbg_glfwCreateTexture(GLuint width, GLuint height, GLint internal_format)
create an empty non-interpolated (NEAREST) GL texture
GLenum simple_program
Simple GLSL program (screen-aligned textured quad)
Definition: fbg_glfw.h:43
GLuint fbg_glfwCreateVAOvu(GLsizeiptr data_count, const GLvoid *data)
create a VAO from vertices + UV data packed into a single array
GLuint fbg_vao
FBG VAO.
Definition: fbg_glfw.h:45
GLuint fbg_glfwCreateShaderFromFile(GLenum type, const char *filename)
create a shader from the content of a file
FB Graphics context data structure.
Definition: fbgraphics.h:123
void fbg_glfwClear()
OpenGL clear.
GLuint fbg_glfwCreateFBO(GLuint texture)
create a FBO
GLuint fbg_glfwCreateProgram(GLuint vertex_shader, GLuint fragment_shader, GLuint geometry_shader)
create a vertex and/or fragment program
Image data structure.
Definition: fbgraphics.h:91
void fbg_glfwFullscreen(struct _fbg *fbg, int enable)
Switch to fullscreen or windowed mode.
GLuint fbg_glfwCreateShader(GLenum type, const GLchar *source)
create a single shader