dos3d

diff src/mingl.c @ 3:0e781cc43178

adding textures
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 21 Nov 2011 10:16:09 +0200
parents f04884489bad
children bce78aaafc68
line diff
     1.1 --- a/src/mingl.c	Mon Nov 21 10:15:37 2011 +0200
     1.2 +++ b/src/mingl.c	Mon Nov 21 10:16:09 2011 +0200
     1.3 @@ -23,11 +23,13 @@
     1.4  #include "mingl.h"
     1.5  #include "mglimpl.h"
     1.6  
     1.7 +
     1.8  #define DOT(a, b)	((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
     1.9  
    1.10  static void transform(vec4_t *res, vec4_t *v, float *mat);
    1.11  static void transform3(vec3_t *res, vec3_t *v, float *mat);
    1.12  static void vertex_proc(struct vertex *vert);
    1.13 +static int calc_shiftmask(int val, int *shiftp, unsigned int *maskp);
    1.14  
    1.15  static struct state st;
    1.16  static struct framebuffer fb;
    1.17 @@ -106,6 +108,11 @@
    1.18  	st.flags &= ~bit;
    1.19  }
    1.20  
    1.21 +int mgl_isenabled(unsigned int bit)
    1.22 +{
    1.23 +	return (st.flags & bit) != 0;
    1.24 +}
    1.25 +
    1.26  void mgl_front_face(int ff)
    1.27  {
    1.28  	st.frontface = ff;
    1.29 @@ -464,3 +471,30 @@
    1.30  	float x = nr * tan(vfov_rad / 2.0);
    1.31  	mgl_frustum(-aspect * x, aspect * x, -x, x, nr, fr);
    1.32  }
    1.33 +
    1.34 +void mgl_teximage(int width, int height, unsigned char *pixels)
    1.35 +{
    1.36 +	st.tex.width = width;
    1.37 +	st.tex.height = height;
    1.38 +	st.tex.pixels = pixels;
    1.39 +
    1.40 +	if(calc_shiftmask(width, &st.tex.xshift, &st.tex.xmask) == -1 ||
    1.41 +			calc_shiftmask(height, &st.tex.yshift, &st.tex.ymask) == -1) {
    1.42 +		st.tex.pixels = 0;
    1.43 +	}
    1.44 +}
    1.45 +
    1.46 +#define MAX_SHIFT	12
    1.47 +static int calc_shiftmask(int val, int *shiftp, unsigned int *maskp)
    1.48 +{
    1.49 +	int i;
    1.50 +
    1.51 +	for(i=0; i<MAX_SHIFT; i++) {
    1.52 +		if((val >> i) == 1) {
    1.53 +			*shiftp = i;
    1.54 +			*maskp = ~(0xffff << i);
    1.55 +			return 0;
    1.56 +		}
    1.57 +	}
    1.58 +	return -1;
    1.59 +}