15 glDeleteBuffers(1, &
buffer);
25 glBindBuffer(GL_ARRAY_BUFFER,
buffer);
26 glBufferData(GL_ARRAY_BUFFER, elem * size, data, GL_STATIC_DRAW);
35 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
buffer);
44 glEnableVertexAttribArray(location);
45 glBindBuffer(GL_ARRAY_BUFFER,
buffer);
46 glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, 0,
nullptr);
51 glDisableVertexAttribArray(location);
63 glGenRenderbuffers(1, &
depth);
64 glBindRenderbuffer(GL_RENDERBUFFER,
depth);
65 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
width,
height);
66 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
depth);
68 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
71 GLenum drawBuffer = GL_COLOR_ATTACHMENT0;
72 glDrawBuffers(1, &drawBuffer);
74 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
78 glDeleteRenderbuffers(1, &
depth);
86 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
103 int r = glGetUniformLocation(
programID, name);
123 glUniform4f(
getUniform(uni), vec.r, vec.g, vec.b, vec.a);
127 glUniformMatrix4fv(
getUniform(uni), 1, GL_FALSE, &mat[0][0]);
140 assert(vertex !=
nullptr);
141 assert(fragment !=
nullptr);
143 GLuint vertexID = glCreateShader(GL_VERTEX_SHADER);
144 GLuint fragmentID = glCreateShader(GL_FRAGMENT_SHADER);
146 GLint result = GL_FALSE;
150 glShaderSource(vertexID, 1, &vertex,
nullptr);
151 glCompileShader(vertexID);
154 glGetShaderiv(vertexID, GL_COMPILE_STATUS, &result);
155 glGetShaderiv(vertexID, GL_INFO_LOG_LENGTH, &logLength);
157 std::vector<char> message(logLength + 1);
158 glGetShaderInfoLog(vertexID, logLength,
nullptr, &message[0]);
159 if (result != GL_TRUE)
162 glDeleteShader(vertexID);
163 glDeleteShader(fragmentID);
168 glShaderSource(fragmentID, 1, &fragment,
nullptr);
169 glCompileShader(fragmentID);
172 glGetShaderiv(fragmentID, GL_COMPILE_STATUS, &result);
173 glGetShaderiv(fragmentID, GL_INFO_LOG_LENGTH, &logLength);
175 std::vector<char> message(logLength + 1);
176 glGetShaderInfoLog(fragmentID, logLength,
nullptr, &message[0]);
177 if (result != GL_TRUE)
180 glDeleteShader(vertexID);
181 glDeleteShader(fragmentID);
192 glGetProgramiv(
programID, GL_LINK_STATUS, &result);
193 glGetProgramiv(
programID, GL_INFO_LOG_LENGTH, &logLength);
195 std::vector<char> message(logLength + 1);
196 glGetProgramInfoLog(
programID, logLength,
nullptr, &message[0]);
197 if (result != GL_TRUE)
200 glDeleteShader(vertexID);
201 glDeleteShader(fragmentID);
206 glDeleteShader(vertexID);
207 glDeleteShader(fragmentID);
228 glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
231 glDepthFunc(GL_LESS);
234 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
268 glDisable(GL_CULL_FACE);
270 glDisable(GL_DEPTH_TEST);
272 glEnable(GL_CULL_FACE);
274 glEnable(GL_DEPTH_TEST);
282 if (mode == GL_TRIANGLES) {
286 if (target ==
nullptr) {
287 glBindFramebuffer(GL_FRAMEBUFFER, 0);
301 glDrawArrays(mode, 0, vertices.
getSize());
314 if (target ==
nullptr) {
315 glBindFramebuffer(GL_FRAMEBUFFER, 0);
326 glDrawArrays(GL_TRIANGLES, 0, vertices.
getSize());
337 if (target ==
nullptr) {
338 glBindFramebuffer(GL_FRAMEBUFFER, 0);
343 unsigned int sz = vertices.
getSize();
344 glm::vec3* buffer =
new glm::vec3[sz];
345 glBindBuffer(GL_ARRAY_BUFFER, vertices.
getBuffer());
346 glGetBufferSubData(GL_ARRAY_BUFFER, 0, sz *
sizeof(glm::vec3), buffer);
349 for (
unsigned int i = 0; i < sz; i++) {
350 glm::vec4 tmp(buffer[i], 1.0f);
352 glm::vec3 res(tmp.x, tmp.y, tmp.z);
365 glDrawElements(GL_TRIANGLES, indices.
getSize(), GL_UNSIGNED_SHORT,
nullptr);
373 if (mode == GL_TRIANGLES) {
377 if (target ==
nullptr) {
378 glBindFramebuffer(GL_FRAMEBUFFER, 0);
388 glDrawArrays(mode, 0, vertices.
getSize());
396 if (mode == GL_TRIANGLES) {
400 if (target ==
nullptr) {
401 glBindFramebuffer(GL_FRAMEBUFFER, 0);
412 glDrawElements(mode, indices.
getSize(), GL_UNSIGNED_SHORT,
nullptr);
423 layout(location = 0) in vec2 vertexPosition_screen;
424 layout(location = 1) in vec2 vertexUV;
431 vec2 halfScreen = screen / 2;
432 vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
434 gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
444 layout(location = 0) out vec4 color;
446 uniform sampler2D textureSampler;
447 uniform vec4 colorVar;
450 color = texture(textureSampler, UV) * colorVar;
459 layout(location = 0) in vec3 vertexPosition_modelspace;
460 layout(location = 1) in vec2 vertexUV;
467 vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
468 -vertexPosition_modelspace.y,
469 vertexPosition_modelspace.z,
471 gl_Position = vec4(-pos.x, pos.yzw);
481 layout(location = 0) out vec4 color;
483 uniform sampler2D textureSampler;
486 color = texture(textureSampler, UV);
495 layout(location = 0) in vec3 vertexPosition_modelspace;
496 layout(location = 1) in vec3 vertexColor;
503 vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
504 -vertexPosition_modelspace.y,
505 vertexPosition_modelspace.z,
507 gl_Position = vec4(-pos.x, pos.yzw);
517 layout(location = 0) out vec4 color_out;
520 color_out = vec4(color, 1);
ShaderTexture(int w=512, int h=512)
static const char * textureShaderFragment
void bufferData(int elem, int size, void *data)
static const char * textShaderVertex
OpenGL Shader Implementation.
void loadUniform(int uni, glm::vec2 vec)
static LogLevel & get(int level)
int compile(const char *vertex, const char *fragment)
static const char * colorShaderFragment
static Shader colorShader
static int bindTexture(unsigned int n, TextureStorage s)
Bind texture to next free texture unit.
static const char * textureShaderVertex
static void drawGL(ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
static unsigned int getTextureID(int n, TextureStorage s)
static const char * textShaderFragment
static Shader textureShader
static const char * colorShaderVertex
int addUniform(const char *name)
static unsigned int vertexArrayID
static int loadBufferSlot(unsigned char *image=nullptr, unsigned int width=256, unsigned int height=256, ColorMode mode=ColorMode::RGBA, unsigned int bpp=32, TextureStorage s=TextureStorage::GAME, int slot=-1, bool filter=true)
Loads Buffer as texture.
static void set2DState(bool on, bool depth=true)
std::vector< unsigned int > uniforms
void unbind(int location)
static glm::i32vec2 getSize()
unsigned int getUniform(int n)