version 1.1 | | version 1.2 |
---|
| | |
#include <stdio.h> | | //#include <stdio.h> |
#include <GL/gl.h> | | #include <GL/gl.h> |
#include <GL/glu.h> | | #include <GL/glu.h> |
#include "3d.h" | | #include "3d.h" |
| | |
#include "palette.h" | | #include "palette.h" |
#include "rle.h" | | #include "rle.h" |
#include "ogl_init.h" | | #include "ogl_init.h" |
| | #include "mono.h" |
| | |
GLfloat tempmatrix[16]; | | GLfloat tempmatrix[16]; |
int r_polyc,r_tpolyc,r_bitmapc; | | int r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc; |
int r_simc; | | |
int r_texcount=0; | | int r_texcount=0; |
#define f2glf(x) (f2fl(x)) | | #define f2glf(x) (f2fl(x)) |
| | |
/*#define fillmatrixrow(dest,source) dest[0]=f2glf(source.x);dest[1]=f2glf(source.y);dest[2]=f2glf(source.z);//printf("%f,%f,%f/",f2glf(source.x),f2glf(source.y),f2glf(source.z)); | | |
| | |
#define ogl_load_matrix(tempmatrix,matrix)\ | | |
fillmatrixrow(tempmatrix,matrix ## rvec);\ | | |
fillmatrixrow((tempmatrix+4),matrix ## uvec);\ | | |
fillmatrixrow((tempmatrix+8),matrix ## fvec);*/ | | |
| | |
#define fillmatrixrow(dest,source) dest[0]=f2glf(source.x);dest[4]=f2glf(source.y);dest[8]=f2glf(source.z);//printf("%f,%f,%f/",f2glf(source.x),f2glf(source.y),f2glf(source.z)); | | |
| | |
#define ogl_load_matrix(tempmatrix,matrix){\ | | |
fillmatrixrow(tempmatrix,matrix ## rvec);\ | | |
fillmatrixrow((tempmatrix+1),matrix ## uvec);\ | | |
fillmatrixrow((tempmatrix+2),matrix ## fvec);} | | |
| | |
#define ogl_mult_vms_matrix(matrix){\ | | |
ogl_load_matrix(tempmatrix,matrix)\ | | |
tempmatrix[3]=tempmatrix[7]=tempmatrix[11]=0;\ | | |
tempmatrix[12]=tempmatrix[13]=tempmatrix[14]=0;\ | | |
tempmatrix[15]=1.0;\ | | |
glMultMatrixf(tempmatrix);} | | |
| | |
//#define ogl_start_instance_matrix(p,o) g3_start_instance_matrix(p,o) | | |
void ogl_start_instance_matrix(vms_vector *pos,vms_matrix *orient){ | | |
r_simc++; | | |
glPushMatrix(); | | |
//glTranslatef(f2glf(pos->x),f2glf(pos->y),f2glf(pos->z)); | | |
glTranslatef(f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); | | |
if (orient){ | | |
ogl_mult_vms_matrix(orient->); | | |
} | | |
} | | |
//#define ogl_done_instance() g3_done_instance() | | |
void ogl_done_instance(void){ | | |
r_simc--; | | |
glPopMatrix(); | | |
} | | |
| | |
#ifdef OGL_TRANSFORM | | |
void ogl_set_view_matrix(void){ | | |
// printf("ogl_set_view_matrix:"); | | |
glMatrixMode(GL_PROJECTION); | | |
glLoadIdentity();//clear matrix | | |
//gluPerspective(90.0,f2fl(fixmuldiv(grd_curscreen->sc_aspect,Canvas_height,Canvas_width)),1.0,1000000.0); | | |
gluPerspective(65.0,(GLfloat)Canvas_width/(GLfloat)Canvas_height,1.0,1000000.0); | | |
//glScalef(1.0,1.0,-1.0); | | |
//glRotatef(180.0,0,1,0); | | |
//glScalef(1.0,1.0,-1.0); | | |
// glRotatef(180.0,1,0,1); | | |
/* glRotatef(180.0,0,1,0); | | |
glRotatef(180.0,0,0,1); | | |
// glScalef(1.0,-1.0,1.0); | | |
glScalef(1.0,-1.0,1.0);*/ | | |
// gluLookAt(0,0,0,0,0,1,0,1,0); | | |
// glScalef(-1.0,-1.0,-1.0); | | |
| | |
// glScalef(1.0,-1.0,1.0); | | |
// glScalef(-1.0,-1.0,1.0); | | |
// glScalef(1.0,-1.0,1.0); | | |
//glTranslatef(f2glf(View_position.x),-f2glf(View_position.y),-f2glf(View_position.z)); | | |
// glScalef(-1.0,-1.0,1.0); | | |
glScalef(1.0,1.0,-1.0); | | |
ogl_mult_vms_matrix(View_matrix.); | | |
//glTranslatef(-f2glf(View_position.x),-f2glf(View_position.y),-f2glf(View_position.z)); | | |
glTranslatef(-f2glf(View_position.x),-f2glf(View_position.y),-f2glf(View_position.z)); | | |
// glScalef(-1.0,-1.0,1.0); | | |
// glScalef(1.0,1.0,-1.0); | | |
glMatrixMode(GL_MODELVIEW); | | |
} | | |
#endif | | |
bool g3_draw_poly(int nv,g3s_point **pointlist) | | bool g3_draw_poly(int nv,g3s_point **pointlist) |
{ | | { |
int c; | | int c; |
| | |
int c; | | int c; |
float l; | | float l; |
r_tpolyc++; | | r_tpolyc++; |
| | /* if (bm->bm_w !=64||bm->bm_h!=64) |
| | printf("g3_draw_tmap w %i h %i\n",bm->bm_w,bm->bm_h);*/ |
glEnable(GL_TEXTURE_2D); | | glEnable(GL_TEXTURE_2D); |
if (bm->gltexture<0) | | if (bm->gltexture<0) |
ogl_loadbmtexture(bm); | | ogl_loadbmtexture(bm); |
| | |
if (bm->bm_flags&BM_FLAG_NO_LIGHTING){ | | if (bm->bm_flags&BM_FLAG_NO_LIGHTING){ |
l=1.0; | | l=1.0; |
}else{ | | }else{ |
l=f2fl(uvl_list[c].l)+gr_palette_gamma/63.0; | | //l=f2fl(uvl_list[c].l)+gr_palette_gamma/63.0; |
| | l=f2fl(uvl_list[c].l); |
} | | } |
glColor3f(l,l,l); | | glColor3f(l,l,l); |
glTexCoord2f(f2glf(uvl_list[c].u),f2glf(uvl_list[c].v)); | | glTexCoord2f(f2glf(uvl_list[c].u),f2glf(uvl_list[c].v)); |
| | |
glDisable(GL_TEXTURE_2D); | | glDisable(GL_TEXTURE_2D); |
// printf("\n"); | | // printf("\n"); |
| | |
| | return 0; |
| | } |
| | bool ogl_ubitmapm(int x, int y,grs_bitmap *bm) |
| | { |
| | GLfloat xo,yo,xs,ys; |
| | r_ubitmapc++; |
| | |
| | xo=x/(float)grd_curscreen->sc_w; |
| | xs=bm->bm_w/(float)grd_curscreen->sc_w; |
| | yo=1.0-y/(float)grd_curscreen->sc_h; |
| | ys=bm->bm_h/(float)grd_curscreen->sc_h; |
| | // printf("g3_draw_bitmap: %f,%f,%f - ",f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); |
| | // printf("(%f,%f,%f) ",f2glf(View_position.x),f2glf(View_position.y),-f2glf(View_position.z)); |
| | |
| | /* glEnable(GL_ALPHA_TEST); |
| | glAlphaFunc(GL_GREATER,0.0);*/ |
| | |
#if 0 | | glEnable(GL_TEXTURE_2D); |
if (bm->gltexture<0) | | if (bm->gltexture<0) |
ogl_loadbmtexture(bm); | | ogl_loadbmtexture(bm); |
glBindTexture(GL_TEXTURE_2D, bm->gltexture); | | glBindTexture(GL_TEXTURE_2D, bm->gltexture); |
| | |
//ogl_start_instance_matrix(pos,NULL); | | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
//ogl_start_instance_matrix(pos,&View_matrix); | | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
g3_start_instance_matrix(pos,&View_matrix); | | |
//glColor3f(l,l,l); | | |
//glScalef(f2fl(width)/64.0,f2fl(height)/64.0,1.0); | | |
glScalef(f2fl(width)*2,f2fl(height)*2,1.0); | | |
glBegin(GL_QUADS); | | glBegin(GL_QUADS); |
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.0); | | glColor3f(1.5,1.5,1.5); |
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, 0.0); | | glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo); |
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0.0); | | glTexCoord2f(1.0, 0.0); glVertex2f(xo+xs, yo); |
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, 0.0); | | glTexCoord2f(1.0, 1.0); glVertex2f(xo+xs, yo-ys); |
| | glTexCoord2f(0.0, 1.0); glVertex2f(xo, yo-ys); |
glEnd(); | | glEnd(); |
ogl_done_instance(); | | glDisable(GL_TEXTURE_2D); |
#endif | | // glDisable(GL_ALPHA_TEST); |
| | |
return 0; | | return 0; |
} | | } |
| | |
vms_vector aoeupos={0,0,-1000*f1_0}; | | vms_vector aoeupos={0,0,-1000*f1_0}; |
vms_matrix aoeuorient=IDENTITY_MATRIX; | | vms_matrix aoeuorient=IDENTITY_MATRIX; |
void ogl_start_frame(void){ | | void ogl_start_frame(void){ |
r_simc=0;r_polyc=0;r_tpolyc=0;r_bitmapc=0; | | r_polyc=0;r_tpolyc=0;r_bitmapc=0;r_ubitmapc=0; |
glClearColor(0.0, 0.0, 0.0, 0.0); | | glClearColor(0.0, 0.0, 0.0, 0.0); |
// glEnable(GL_ALPHA_TEST); | | // glEnable(GL_ALPHA_TEST); |
// glAlphaFunc(GL_GREATER,0.0); | | // glAlphaFunc(GL_GREATER,0.0); |
| | |
} | | } |
void ogl_end_frame(void){ | | void ogl_end_frame(void){ |
| | |
printf("ogl_end_frame: rendered %i flat polys, %i tmapped polys, %i bitmaps, simc=%i\n",r_polyc,r_tpolyc,r_bitmapc,r_simc); | | mprintf((0,"ogl_end_frame: rendered %i flat polys, %i tmapped polys, %i sprites, %i ubitmaps\n",r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc)); |
glMatrixMode(GL_PROJECTION); | | glMatrixMode(GL_PROJECTION); |
glLoadIdentity();//clear matrix | | glLoadIdentity();//clear matrix |
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); | | glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); |
glMatrixMode(GL_MODELVIEW); | | glMatrixMode(GL_MODELVIEW); |
glLoadIdentity();//clear matrix | | glLoadIdentity();//clear matrix |
glDisable(GL_BLEND); | | // glDisable(GL_BLEND); |
//glDisable(GL_ALPHA_TEST); | | //glDisable(GL_ALPHA_TEST); |
//gluPerspective(90.0,(GLfloat)(grd_curscreen->sc_w*3)/(GLfloat)(grd_curscreen->sc_h*4),1.0,1000000.0); | | //gluPerspective(90.0,(GLfloat)(grd_curscreen->sc_w*3)/(GLfloat)(grd_curscreen->sc_h*4),1.0,1000000.0); |
// ogl_swap_buffers();//platform specific code | | // ogl_swap_buffers();//platform specific code |
| | |
// texp=texbuf; | | // texp=texbuf; |
if (width*height>sizeof(texbuf)) | | if (width*height>sizeof(texbuf)) |
Error("toobig"); | | Error("toobig"); |
printf("ogl_loadtexture(%p,%i,%i,%p):",data,width,height,texid); | | |
for (i=0;i<width*height;i++){ | | for (i=0;i<width*height;i++){ |
c=data[i]; | | c=data[i]; |
if (c==255){ | | if (c==255){ |
(*(texp++))=0; | | (*(texp++))=0; |
(*(texp++))=0; | | (*(texp++))=0; |
(*(texp++))=0; | | (*(texp++))=0; |
(*(texp++))=0; | | (*(texp++))=0;//transparent pixel |
}else{ | | }else{ |
(*(texp++))=gr_palette[c*3]*4; | | (*(texp++))=gr_palette[c*3]*4; |
(*(texp++))=gr_palette[c*3+1]*4; | | (*(texp++))=gr_palette[c*3+1]*4; |
(*(texp++))=gr_palette[c*3+2]*4; | | (*(texp++))=gr_palette[c*3+2]*4; |
(*(texp++))=255; | | (*(texp++))=255;//not transparent |
} | | } |
} | | } |
| | |
| | |
| | |
glBindTexture(GL_TEXTURE_2D, *texid); | | glBindTexture(GL_TEXTURE_2D, *texid); |
| | |
// glTexParameterf(GL_TEXTiURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | | //TODO: make texturing mode an option |
| | // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| | // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| | // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| | // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); | | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
//GL_UNSIGNED_INT_8_8_8_8 | | |
/* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, // RGBA textures. | | /* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, // RGBA textures. |
width, height, 0, GL_RGBA, | | width, height, 0, GL_RGBA, |
GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. | | GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. |
| | |
gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, | | gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, |
height, GL_RGBA, GL_UNSIGNED_BYTE, texbuf); | | height, GL_RGBA, GL_UNSIGNED_BYTE, texbuf); |
r_texcount++; | | r_texcount++; |
printf("%i (%i)\n",*texid,r_texcount); | | mprintf((0,"ogl_loadtexture(%p,%i,%i,%p):%i (%i)\n",data,width,height,texid,*texid,r_texcount)); |
| | |
} | | } |
unsigned char decodebuf[512*512]; | | unsigned char decodebuf[512*512]; |
void ogl_loadbmtexture(grs_bitmap *bm){ | | void ogl_loadbmtexture(grs_bitmap *bm){ |
unsigned char *buf=bm->bm_data; | | unsigned char *buf=bm->bm_data; |
if (bm->bm_flags&&BM_FLAG_RLE){ | | if (bm->bm_flags & BM_FLAG_RLE){ |
unsigned char * dbits; | | unsigned char * dbits; |
unsigned char * sbits; | | unsigned char * sbits; |
int i; | | int i; |
| | |
void ogl_freebmtexture(grs_bitmap *bm){ | | void ogl_freebmtexture(grs_bitmap *bm){ |
if (bm->gltexture>=0){ | | if (bm->gltexture>=0){ |
r_texcount--; | | r_texcount--; |
printf("ogl_freebmtexture(%p,%p):%i (%i left)\n",bm->bm_data,&bm->gltexture,bm->gltexture,r_texcount); | | mprintf((0,"ogl_freebmtexture(%p,%p):%i (%i left)\n",bm->bm_data,&bm->gltexture,bm->gltexture,r_texcount)); |
glDeleteTextures( 1, &bm->gltexture ); | | glDeleteTextures( 1, &bm->gltexture ); |
bm->gltexture=-1; | | bm->gltexture=-1; |
} | | } |