add util for copying a texture
This commit is contained in:
parent
f8f62312f9
commit
0bdb9a18fe
3 changed files with 41 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
#ifndef DEMO_UTILS_H
|
#ifndef DEMO_UTILS_H
|
||||||
#define DEMO_UTILS_H 1
|
#define DEMO_UTILS_H 1
|
||||||
|
|
||||||
|
#include <GL4D/gl4dh.h>
|
||||||
#include <GL4D/gl4duw_SDL2.h>
|
#include <GL4D/gl4duw_SDL2.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -32,4 +33,7 @@ void rotate_vec(GLfloat *, GLfloat);
|
||||||
// Load an image into a GL texture
|
// Load an image into a GL texture
|
||||||
void load_img(const char *filename, GLuint texture);
|
void load_img(const char *filename, GLuint texture);
|
||||||
|
|
||||||
|
// Copy a texture
|
||||||
|
void copy_texture(GLuint, GLuint);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,7 @@ static void init(void) {
|
||||||
|
|
||||||
glGenTextures(2, _texId);
|
glGenTextures(2, _texId);
|
||||||
load_img("images/wall.png", _texId[0]);
|
load_img("images/wall.png", _texId[0]);
|
||||||
load_img("images/wall.png", _texId[1]);
|
copy_texture(_texId[0], _texId[1]);
|
||||||
|
|
||||||
TTF_Font *font = NULL;
|
TTF_Font *font = NULL;
|
||||||
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
|
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
|
||||||
|
|
36
src/utils.c
36
src/utils.c
|
@ -50,3 +50,39 @@ void load_img(const char *filename, GLuint texture) {
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copy_texture(GLuint src, GLuint dst) {
|
||||||
|
if (!(src || dst)) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Erreur copie texture: Source/Destination pas initalisée\n");
|
||||||
|
exit(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, src);
|
||||||
|
GLint w, h;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
|
|
||||||
|
SDL_Surface *s;
|
||||||
|
if (!(s = SDL_CreateRGBSurface(0, w, h, 32, R_MASK, G_MASK, B_MASK,
|
||||||
|
A_MASK))) {
|
||||||
|
fprintf(stderr, "Erreur copie texture : %s\n", SDL_GetError());
|
||||||
|
exit(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copie des données
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, s->pixels);
|
||||||
|
|
||||||
|
// Copy data
|
||||||
|
glBindTexture(GL_TEXTURE_2D, dst);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, s->pixels);
|
||||||
|
|
||||||
|
SDL_FreeSurface(s);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
Reference in a new issue