libpsys
diff examples/simple/simple.c @ 2:6e5342a2529a
more stuff done
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sun, 25 Sep 2011 04:26:51 +0300 |
parents | 874a942853ad |
children | a10f19674147 |
line diff
1.1 --- a/examples/simple/simple.c Sat Sep 24 20:44:42 2011 +0300 1.2 +++ b/examples/simple/simple.c Sun Sep 25 04:26:51 2011 +0300 1.3 @@ -1,5 +1,6 @@ 1.4 #include <stdio.h> 1.5 #include <stdlib.h> 1.6 +#include <assert.h> 1.7 1.8 #ifndef __APPLE__ 1.9 #include <GL/glut.h> 1.10 @@ -8,6 +9,7 @@ 1.11 #endif 1.12 1.13 #include <vmath.h> 1.14 +#include <imago2.h> 1.15 #include "psys.h" 1.16 1.17 void disp(void); 1.18 @@ -17,8 +19,10 @@ 1.19 void mouse(int bn, int state, int x, int y); 1.20 void motion(int x, int y); 1.21 vec3_t get_mouse_hit(float x, float y); 1.22 +unsigned int load_texture(const char *fname); 1.23 1.24 struct psys_emitter *ps; 1.25 +unsigned int tex; 1.26 1.27 int main(int argc, char **argv) 1.28 { 1.29 @@ -34,13 +38,19 @@ 1.30 glutMotionFunc(motion); 1.31 glutIdleFunc(idle); 1.32 1.33 - glEnable(GL_CULL_FACE); 1.34 + glClearColor(0.05, 0.05, 0.05, 1); 1.35 + 1.36 + if(!(tex = load_texture("pimg.png"))) { 1.37 + fprintf(stderr, "failed to load the FUCKING TEXTURE GOD DAMN IT\n"); 1.38 + return 1; 1.39 + } 1.40 1.41 if(!(ps = psys_create())) { 1.42 return 1; 1.43 } 1.44 - psys_set_grav(ps, v3_cons(0, -1, 0), 0); 1.45 + psys_set_grav(ps, v3_cons(0, -9, 0), 0); 1.46 psys_set_life(ps, 2, 0); 1.47 + psys_set_texture(ps, tex); 1.48 1.49 glutMainLoop(); 1.50 return 0; 1.51 @@ -61,6 +71,7 @@ 1.52 psys_draw(ps); 1.53 1.54 glutSwapBuffers(); 1.55 + assert(glGetError() == GL_NO_ERROR); 1.56 } 1.57 1.58 void idle(void) 1.59 @@ -90,7 +101,7 @@ 1.60 { 1.61 bnstate[bn - GLUT_LEFT_BUTTON] = state == GLUT_DOWN; 1.62 if(bn == GLUT_LEFT_BUTTON) { 1.63 - psys_set_rate(ps, state == GLUT_DOWN ? 1.0 : 0.0, 0); 1.64 + psys_set_rate(ps, state == GLUT_DOWN ? 30.0 : 0.0, 0); 1.65 psys_set_pos(ps, get_mouse_hit(x, y), 0); 1.66 } 1.67 } 1.68 @@ -131,3 +142,25 @@ 1.69 1.70 return res; 1.71 } 1.72 + 1.73 +unsigned int load_texture(const char *fname) 1.74 +{ 1.75 + void *pixels; 1.76 + int xsz, ysz; 1.77 + unsigned int tex; 1.78 + 1.79 + if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) { 1.80 + return 0; 1.81 + } 1.82 + 1.83 + glGenTextures(1, &tex); 1.84 + glBindTexture(GL_TEXTURE_2D, tex); 1.85 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.86 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.87 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 1.88 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 1.89 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 1.90 + img_free_pixels(pixels); 1.91 + 1.92 + return tex; 1.93 +}