libpsys
diff src/psys_gl.c @ 5:613d2bf3ea1f
almost finished with the reorg
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Tue, 27 Sep 2011 07:42:32 +0300 |
parents | 133094e2f5a5 |
children | 9c24273f211b |
line diff
1.1 --- a/src/psys_gl.c Mon Sep 26 18:25:18 2011 +0300 1.2 +++ b/src/psys_gl.c Tue Sep 27 07:42:32 2011 +0300 1.3 @@ -1,10 +1,19 @@ 1.4 +#include <string.h> 1.5 +#include <errno.h> 1.6 + 1.7 #ifndef __APPLE__ 1.8 +#ifdef WIN32 1.9 +#include <windows.h> 1.10 +#endif 1.11 + 1.12 #include <GL/gl.h> 1.13 #else 1.14 #include <OpenGL/gl.h> 1.15 #endif 1.16 1.17 -#include "psys_impl.h" 1.18 +#include <imago2.h> 1.19 +#include "psys.h" 1.20 +#include "psys_gl.h" 1.21 1.22 void psys_gl_draw_start(struct psys_emitter *em, void *cls) 1.23 { 1.24 @@ -25,9 +34,9 @@ 1.25 glEnable(GL_BLEND); 1.26 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 1.27 1.28 - if(em->tex) { 1.29 + if(em->attr.tex) { 1.30 glEnable(GL_TEXTURE_2D); 1.31 - glBindTexture(GL_TEXTURE_2D, em->tex); 1.32 + glBindTexture(GL_TEXTURE_2D, em->attr.tex); 1.33 } 1.34 1.35 glDepthMask(0); 1.36 @@ -63,3 +72,31 @@ 1.37 glMatrixMode(GL_MODELVIEW); 1.38 glPopMatrix(); 1.39 } 1.40 + 1.41 + 1.42 +unsigned int psys_gl_load_texture(const char *fname, void *cls) 1.43 +{ 1.44 + unsigned int tex; 1.45 + void *pixels; 1.46 + int xsz, ysz; 1.47 + 1.48 + if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) { 1.49 + return 0; 1.50 + } 1.51 + 1.52 + glGenTextures(1, &tex); 1.53 + glBindTexture(GL_TEXTURE_2D, tex); 1.54 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.55 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.56 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 1.57 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 1.58 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, xsz, ysz, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 1.59 + 1.60 + img_free_pixels(pixels); 1.61 + return tex; 1.62 +} 1.63 + 1.64 +void psys_gl_unload_texture(unsigned int tex, void *cls) 1.65 +{ 1.66 + glDeleteTextures(1, &tex); 1.67 +}