aboutsummaryrefslogtreecommitdiff
path: root/fb.c
blob: e9ebcdcd6cbf4ebc5c4d8184b5fa6d73457c96e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include "fb.h"
#include "die.h"
#include "consts.h"

GLuint init_fb() {
	GLuint fbo;
	glGenFramebuffers(1, &fbo);

	// configure newly created framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	GLuint buffer;
	glGenTextures(1, &buffer);
	glBindTexture(GL_TEXTURE_2D, buffer);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, RES_H, RES_V, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
	if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		die("can't initialize framebuffer??\n");

	// use default framebuffer again
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	return fbo;
}