libpsys

diff src/psys_gl.c @ 0:1c8eb90a6989

initial commit
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sat, 24 Sep 2011 07:22:07 +0300
parents
children 874a942853ad
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/psys_gl.c	Sat Sep 24 07:22:07 2011 +0300
     1.3 @@ -0,0 +1,57 @@
     1.4 +#ifndef __APPLE__
     1.5 +#include <GL/gl.h>
     1.6 +#else
     1.7 +#include <OpenGL/gl.h>
     1.8 +#endif
     1.9 +
    1.10 +#include "psys_impl.h"
    1.11 +
    1.12 +void psys_gl_draw_start(struct psys_emitter *em, void *cls)
    1.13 +{
    1.14 +	float xform[16];
    1.15 +
    1.16 +	glMatrixMode(GL_MODELVIEW);
    1.17 +	glPushMatrix();
    1.18 +
    1.19 +	glGetFloatv(GL_MODELVIEW_MATRIX, xform);
    1.20 +	xform[3] = xform[7] = xform[11] = xform[12] = xform[13] = xform[14] = 0.0f;
    1.21 +	xform[15] = 1.0f;
    1.22 +
    1.23 +	glLoadMatrixf(xform);
    1.24 +
    1.25 +	glPushAttrib(GL_ENABLE_BIT);
    1.26 +	glDisable(GL_LIGHTING);
    1.27 +
    1.28 +	glDepthMask(0);
    1.29 +
    1.30 +	glBegin(GL_QUADS);
    1.31 +	glColor3f(1, 1, 1);
    1.32 +}
    1.33 +
    1.34 +void psys_gl_draw(struct psys_emitter *em, struct psys_particle *p, void *cls)
    1.35 +{
    1.36 +	float hsz = p->size / 2.0;
    1.37 +
    1.38 +	glTexCoord2f(0, 0);
    1.39 +	glVertex3f(p->pos.x - hsz, p->pos.y - hsz, p->pos.z);
    1.40 +
    1.41 +	glTexCoord2f(1, 0);
    1.42 +	glVertex3f(p->pos.x + hsz, p->pos.y - hsz, p->pos.z);
    1.43 +
    1.44 +	glTexCoord2f(1, 1);
    1.45 +	glVertex3f(p->pos.x + hsz, p->pos.y + hsz, p->pos.z);
    1.46 +
    1.47 +	glTexCoord2f(0, 1);
    1.48 +	glVertex3f(p->pos.x - hsz, p->pos.y + hsz, p->pos.z);
    1.49 +}
    1.50 +
    1.51 +void psys_gl_draw_end(struct psys_emitter *em, void *cls)
    1.52 +{
    1.53 +	glEnd();
    1.54 +
    1.55 +	glDepthMask(1);
    1.56 +	glPopAttrib();
    1.57 +
    1.58 +	glMatrixMode(GL_MODELVIEW);
    1.59 +	glPopMatrix();
    1.60 +}