Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Created December 12, 2017 10:28
Show Gist options
  • Save rdeioris/8c46ef34eacb76a990afed71379f252c to your computer and use it in GitHub Desktop.
Save rdeioris/8c46ef34eacb76a990afed71379f252c to your computer and use it in GitHub Desktop.
#include <aiv_opengl.h>
#include <stdio.h>
#include <stdlib.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
aiv_opengl_context_t context;
int main(int argc, char *argv[])
{
context.width = 800;
context.height = 800;
context.title = "OpenGL Example";
context.major = 3;
context.minor = 3;
if (aiv_opengl_context_init(&context))
{
fprintf(stderr, "error while initializing aiv_opengl_context\n");
return -1;
}
glViewport(0, 0, context.width, context.height);
glClearColor(0, 0, 0, 1);
size_t nframes = 128;
int width = 800;
int height = 800;
unsigned char **frames = malloc(nframes * sizeof(unsigned char *));
for(int i=0;i<nframes;i++)
{
char filename[1024];
snprintf(filename, 1024, "screenshot_%d.bmp", i);
int x, y, n;
frames[i] = stbi_load(filename, &x, &y, &n, 0);
}
GLuint tex;
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
// NOTE: you need to always specify the filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLuint fb1;
glGenFramebuffers(1, &fb1);
glBindFramebuffer(GL_FRAMEBUFFER, fb1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
int current_frame = 0;
while(!context.closed)
{
glBindFramebuffer(GL_FRAMEBUFFER, fb1);
glClear(GL_COLOR_BUFFER_BIT);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, frames[current_frame]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, frames[current_frame]);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb1);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
aiv_opengl_context_swap(&context);
current_frame++;
if (current_frame >= nframes)
current_frame = 0;
}
aiv_opengl_context_destroy(&context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment