Animated pictures; FPS counter

This commit is contained in:
Caesar2011
2016-09-13 16:11:01 +02:00
parent f99b8dab83
commit 449060a463
17 changed files with 220 additions and 57 deletions

View File

@@ -1,11 +1,10 @@
// http://stackoverflow.com/questions/6005076/building-glew-on-windows-with-mingw
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <SDL2/SDL.h>
#include <fstream>
#include <stdexcept>
#include <dirent.h>
#include "loaders.h"
int main(int argc, char* args[]) {
@@ -23,8 +22,8 @@ int main(int argc, char* args[]) {
return 1;
}
/* Create a windowed mode window and its OpenGL context */
glfwSetWindowSizeLimits(window, 640, 480, 640, 480);
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
glfwSetWindowSizeLimits(window, 640, 480, 640, 480);
if (!window) {
glfwTerminate();
return 1;
@@ -89,16 +88,23 @@ int main(int argc, char* args[]) {
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
int lenTexFG = 10;
GLint texFGs[lenTexFG];
char buffer[50];
texBG = LoadTexture("../img/backgrounds/sky.jpg",&textw2,&texth2);
texFG = LoadTexture("../img/tests/flieger.jpg",&textw,&texth);
printf("Tex1: %d\n", texFG);
for (int i=0; i<lenTexFG; i++) {
snprintf(buffer, sizeof(buffer), "../img/foregrounds/surfing/%d.jpg", i);
texFGs[i] = LoadTexture(buffer,&textw,&texth);
}
texFG = LoadTexture("../img/foregrounds/surfing/0.jpg",&textw,&texth);
glfwSetWindowSize(window, textw, texth);
glViewport(0, 0, textw, texth);
glfwSetWindowSizeLimits(window, textw, texth, textw, texth);
// The texture we're going to render to
GLuint renderedTexture;
glGenTextures(1, &renderedTexture);
@@ -130,8 +136,6 @@ int main(int argc, char* args[]) {
GLint textureLocFore = glGetUniformLocation(programRefineID, "foreground");
GLint textureLocBack = glGetUniformLocation(programRefineID, "background");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texFG);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texBG);
glActiveTexture(GL_TEXTURE2);
@@ -148,11 +152,31 @@ int main(int argc, char* args[]) {
printf("Height: %f\n", 1.0f/texth);
int loopNumber = -1;
double lastTime = glfwGetTime();
int nbFrames = 0;
// INIT END
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
/* Render here */
loopNumber++;
if (loopNumber >= lenTexFG) {
loopNumber = 0;
}
// Measure speed
double currentTime = glfwGetTime();
nbFrames++;
if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1 sec ago
// printf and reset timer
printf("%f ms/frame\n", 1000.0/double(nbFrames));
nbFrames = 0;
lastTime += 1.0;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texFGs[loopNumber]);
// Render to our framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
//glBindFramebuffer(GL_FRAMEBUFFER, 0);