| version 1.15 |  | version 1.16 | 
|---|
|  |  |  | 
| #include <GL/gl.h> |  | #include <GL/gl.h> | 
| #include <GL/glu.h> |  | #include <GL/glu.h> | 
| #include <string.h> |  | #include <string.h> | 
|  |  | #include <math.h> | 
| #include "ogl_init.h" |  | #include "ogl_init.h" | 
| #include "3d.h" |  | #include "3d.h" | 
| #include "piggy.h" |  | #include "piggy.h" | 
|  |  |  | 
| int ogl_rgba2_ok=1; |  | int ogl_rgba2_ok=1; | 
| int ogl_readpixels_ok=1; |  | int ogl_readpixels_ok=1; | 
|  |  |  | 
|  |  | int sphereh=0; | 
|  |  | int circleh5=0; | 
|  |  | int circleh10=0; | 
|  |  | int cross_lh[2]={0,0}; | 
|  |  | int primary_lh[3]={0,0,0}; | 
|  |  | int secondary_lh[5]={0,0,0,0,0}; | 
| /*int lastbound=-1; |  | /*int lastbound=-1; | 
|  |  |  | 
| #define OGL_BINDTEXTURE(a) if(gr_badtexture>0) glBindTexture(GL_TEXTURE_2D, 0);\ |  | #define OGL_BINDTEXTURE(a) if(gr_badtexture>0) glBindTexture(GL_TEXTURE_2D, 0);\ | 
|  |  |  | 
| } |  | } | 
| void ogl_smash_texture_list_internal(void){ |  | void ogl_smash_texture_list_internal(void){ | 
| int i; |  | int i; | 
|  |  | sphereh=0; | 
|  |  | circleh5=0; | 
|  |  | circleh10=0; | 
|  |  | memset(cross_lh,0,sizeof(cross_lh)); | 
|  |  | memset(primary_lh,0,sizeof(primary_lh)); | 
|  |  | memset(secondary_lh,0,sizeof(secondary_lh)); | 
| for (i=0;i<OGL_TEXTURE_LIST_SIZE;i++){ |  | for (i=0;i<OGL_TEXTURE_LIST_SIZE;i++){ | 
| ogl_texture_list[i].handle=0; |  | ogl_texture_list[i].handle=0; | 
| ogl_texture_list[i].wrapstate=-1; |  | ogl_texture_list[i].wrapstate=-1; | 
|  |  |  | 
| glEnd(); |  | glEnd(); | 
| return 1; |  | return 1; | 
| } |  | } | 
|  |  | void ogl_drawcircle2(int nsides,int type,float xsc,float xo,float ysc,float yo){ | 
|  |  | int i; | 
|  |  | float ang; | 
|  |  | glBegin(type); | 
|  |  | for (i=0; i<nsides; i++) { | 
|  |  | ang = 2.0*M_PI*i/nsides; | 
|  |  | glVertex2f(cosf(ang)*xsc+xo,sinf(ang)*ysc+yo); | 
|  |  | } | 
|  |  | glEnd(); | 
|  |  | } | 
|  |  | void ogl_drawcircle(int nsides,int type){ | 
|  |  | int i; | 
|  |  | float ang; | 
|  |  | glBegin(type); | 
|  |  | for (i=0; i<nsides; i++) { | 
|  |  | ang = 2.0*M_PI*i/nsides; | 
|  |  | glVertex2f(cosf(ang),sinf(ang)); | 
|  |  | } | 
|  |  | glEnd(); | 
|  |  | } | 
|  |  | int circle_list_init(int nsides,int type,int mode) { | 
|  |  | int hand=glGenLists(1); | 
|  |  | glNewList(hand, mode); | 
|  |  | /* draw a unit radius circle in xy plane centered on origin */ | 
|  |  | ogl_drawcircle(nsides,type); | 
|  |  | glEndList(); | 
|  |  | return hand; | 
|  |  | } | 
|  |  | float bright_g[4]={	32.0/256,	252.0/256,	32.0/256}; | 
|  |  | float dark_g[4]={	32.0/256,	148.0/256,	32.0/256}; | 
|  |  | float darker_g[4]={	32.0/256,	128.0/256,	32.0/256}; | 
|  |  | void ogl_draw_reticle(int cross,int primary,int secondary){ | 
|  |  | float scale=(float)Canvas_height/(float)grd_curscreen->sc_h; | 
|  |  | glPushMatrix(); | 
|  |  | //	glTranslatef(0.5,0.5,0); | 
|  |  | glTranslatef((grd_curcanv->cv_bitmap.bm_w/2+grd_curcanv->cv_bitmap.bm_x)/(float)last_width,1.0-(grd_curcanv->cv_bitmap.bm_h/2+grd_curcanv->cv_bitmap.bm_y)/(float)last_height,0); | 
|  |  | glScalef(scale/320.0,scale/200.0,scale);//the positions are based upon the standard reticle at 320x200 res. | 
|  |  |  | 
|  |  | OGL_DISABLE(TEXTURE_2D); | 
|  |  |  | 
|  |  | if (!cross_lh[cross]){ | 
|  |  | cross_lh[cross]=glGenLists(1); | 
|  |  | glNewList(cross_lh[cross], GL_COMPILE_AND_EXECUTE); | 
|  |  | glBegin(GL_LINES); | 
|  |  | //cross top left | 
|  |  | glColor3fv(darker_g); | 
|  |  | glVertex2f(-4.0,4.0); | 
|  |  | if (cross) | 
|  |  | glColor3fv(bright_g); | 
|  |  | else | 
|  |  | glColor3fv(dark_g); | 
|  |  | glVertex2f(-2.0,2.0); | 
|  |  |  | 
|  |  | //cross bottom left | 
|  |  | glColor3fv(dark_g); | 
|  |  | glVertex2f(-3.0,-2.0); | 
|  |  | if (cross) | 
|  |  | glColor3fv(bright_g); | 
|  |  | glVertex2f(-2.0,-1.0); | 
|  |  |  | 
|  |  | //cross top right | 
|  |  | glColor3fv(darker_g); | 
|  |  | glVertex2f(4.0,4.0); | 
|  |  | if (cross) | 
|  |  | glColor3fv(bright_g); | 
|  |  | else | 
|  |  | glColor3fv(dark_g); | 
|  |  | glVertex2f(2.0,2.0); | 
|  |  |  | 
|  |  | //cross bottom right | 
|  |  | glColor3fv(dark_g); | 
|  |  | glVertex2f(3.0,-2.0); | 
|  |  | if (cross) | 
|  |  | glColor3fv(bright_g); | 
|  |  | glVertex2f(2.0,-1.0); | 
|  |  |  | 
|  |  | glEnd(); | 
|  |  | glEndList(); | 
|  |  | }else | 
|  |  | glCallList(cross_lh[cross]); | 
|  |  |  | 
|  |  | //	if (Canvas_height>200) | 
|  |  | //		glLineWidth(Canvas_height/(float)200); | 
|  |  | if (!primary_lh[primary]){ | 
|  |  | primary_lh[primary]=glGenLists(1); | 
|  |  | glNewList(primary_lh[primary], GL_COMPILE_AND_EXECUTE); | 
|  |  |  | 
|  |  | glColor3fv(dark_g); | 
|  |  | glBegin(GL_LINES); | 
|  |  | //left primary bar | 
|  |  | glVertex2f(-14.0,-8.0); | 
|  |  | glVertex2f(-8.0,-5.0); | 
|  |  | //right primary bar | 
|  |  | glVertex2f(14.0,-8.0); | 
|  |  | glVertex2f(8.0,-5.0); | 
|  |  | glEnd(); | 
|  |  | if (primary==0) | 
|  |  | glColor3fv(dark_g); | 
|  |  | else | 
|  |  | glColor3fv(bright_g); | 
|  |  | //left upper | 
|  |  | ogl_drawcircle2(6,GL_POLYGON,1.5,-7.0,1.5,-5.0); | 
|  |  | //right upper | 
|  |  | ogl_drawcircle2(6,GL_POLYGON,1.5,7.0,1.5,-5.0); | 
|  |  | if (primary!=2) | 
|  |  | glColor3fv(dark_g); | 
|  |  | else | 
|  |  | glColor3fv(bright_g); | 
|  |  | //left lower | 
|  |  | ogl_drawcircle2(4,GL_POLYGON,1.0,-14.0,1.0,-8.0); | 
|  |  | //right lower | 
|  |  | ogl_drawcircle2(4,GL_POLYGON,1.0,14.0,1.0,-8.0); | 
|  |  |  | 
|  |  | glEndList(); | 
|  |  | }else | 
|  |  | glCallList(primary_lh[primary]); | 
|  |  | //	if (Canvas_height>200) | 
|  |  | //		glLineWidth(1); | 
|  |  |  | 
|  |  | if (!secondary_lh[secondary]){ | 
|  |  | secondary_lh[secondary]=glGenLists(1); | 
|  |  | glNewList(secondary_lh[secondary], GL_COMPILE_AND_EXECUTE); | 
|  |  | if (secondary<=2){ | 
|  |  | //left secondary | 
|  |  | if (secondary!=1) | 
|  |  | glColor3fv(dark_g); | 
|  |  | else | 
|  |  | glColor3fv(bright_g); | 
|  |  | ogl_drawcircle2(6,GL_LINE_LOOP,2.0,-10.0,2.0,-1.0); | 
|  |  | //right secondary | 
|  |  | if (secondary!=2) | 
|  |  | glColor3fv(dark_g); | 
|  |  | else | 
|  |  | glColor3fv(bright_g); | 
|  |  | ogl_drawcircle2(6,GL_LINE_LOOP,2.0,10.0,2.0,-1.0); | 
|  |  | }else{ | 
|  |  | //bottom/middle secondary | 
|  |  | if (secondary!=4) | 
|  |  | glColor3fv(dark_g); | 
|  |  | else | 
|  |  | glColor3fv(bright_g); | 
|  |  | ogl_drawcircle2(6,GL_LINE_LOOP,2.0,0.0,2.0,-7.0); | 
|  |  | } | 
|  |  | glEndList(); | 
|  |  | }else | 
|  |  | glCallList(secondary_lh[secondary]); | 
|  |  |  | 
|  |  | glPopMatrix(); | 
|  |  | } | 
| int g3_draw_sphere(g3s_point *pnt,fix rad){ |  | int g3_draw_sphere(g3s_point *pnt,fix rad){ | 
| int c; |  | int c; | 
| c=grd_curcanv->cv_color; |  | c=grd_curcanv->cv_color; | 
| OGL_DISABLE(TEXTURE_2D); |  | OGL_DISABLE(TEXTURE_2D); | 
| glPointSize(f2glf(rad)); |  | //	glPointSize(f2glf(rad)); | 
| glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |  | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); | 
| glBegin(GL_POINTS); |  | //	glBegin(GL_POINTS); | 
| glVertex3f(f2glf(pnt->p3_vec.x),f2glf(pnt->p3_vec.y),-f2glf(pnt->p3_vec.z)); |  | //	glVertex3f(f2glf(pnt->p3_vec.x),f2glf(pnt->p3_vec.y),-f2glf(pnt->p3_vec.z)); | 
| glEnd(); |  | //	glEnd(); | 
|  |  | glPushMatrix(); | 
|  |  | glTranslatef(f2glf(pnt->p3_vec.x),f2glf(pnt->p3_vec.y),-f2glf(pnt->p3_vec.z)); | 
|  |  | glScalef(f2glf(rad),f2glf(rad),f2glf(rad)); | 
|  |  | if (!sphereh) sphereh=circle_list_init(20,GL_POLYGON,GL_COMPILE_AND_EXECUTE); | 
|  |  | else glCallList(sphereh); | 
|  |  | glPopMatrix(); | 
| return 0; |  | return 0; | 
|  |  |  | 
| } |  | } | 
|  |  | int gr_ucircle(fix xc1,fix yc1,fix r1){//dunno if this really works, radar doesn't seem to.. hm.. | 
|  |  | int c; | 
|  |  | c=grd_curcanv->cv_color; | 
|  |  | OGL_DISABLE(TEXTURE_2D); | 
|  |  | //	glPointSize(f2glf(rad)); | 
|  |  | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); | 
|  |  | //	glBegin(GL_POINTS); | 
|  |  | //	glVertex3f(f2glf(pnt->p3_vec.x),f2glf(pnt->p3_vec.y),-f2glf(pnt->p3_vec.z)); | 
|  |  | //	glEnd(); | 
|  |  | glPushMatrix(); | 
|  |  | mprintf((0,"circle: %f(%i),%f(%i),%f\n",(f2fl(xc1)+grd_curcanv->cv_bitmap.bm_x)/(float)last_width,f2i(xc1),(f2fl(yc1)+grd_curcanv->cv_bitmap.bm_y)/(float)last_height,f2i(yc1),f2fl(r1))); | 
|  |  | glTranslatef( | 
|  |  | (f2fl(xc1)+grd_curcanv->cv_bitmap.bm_x)/(float)last_width, | 
|  |  | 1.0-(f2fl(yc1)+grd_curcanv->cv_bitmap.bm_y)/(float)last_height,0); | 
|  |  | glScalef(f2fl(r1),f2fl(r1),f2fl(r1)); | 
|  |  | if (r1<=i2f(5)){ | 
|  |  | if (!circleh5) circleh5=circle_list_init(5,GL_LINE_LOOP,GL_COMPILE_AND_EXECUTE); | 
|  |  | else glCallList(circleh5); | 
|  |  | }else{ | 
|  |  | if (!circleh10) circleh10=circle_list_init(10,GL_LINE_LOOP,GL_COMPILE_AND_EXECUTE); | 
|  |  | else glCallList(circleh10); | 
|  |  | } | 
|  |  | glPopMatrix(); | 
|  |  | return 0; | 
|  |  | } | 
|  |  | int gr_circle(fix xc1,fix yc1,fix r1){ | 
|  |  | return gr_ucircle(xc1,yc1,r1); | 
|  |  | } | 
|  |  |  | 
| bool g3_draw_poly(int nv,g3s_point **pointlist) |  | bool g3_draw_poly(int nv,g3s_point **pointlist) | 
| { |  | { | 
|  |  |  | 
| } |  | } | 
| #endif |  | #endif | 
| bool ogl_ubitblt_tolinear(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest){ |  | bool ogl_ubitblt_tolinear(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest){ | 
| int i,j; |  | #if 1 | 
|  |  | grs_bitmap tmp; | 
| unsigned char *d,*s; |  | unsigned char *d,*s; | 
|  |  | int i,j; | 
|  |  | int w1,h1; | 
|  |  | char data[1024*1024]; | 
|  |  | //	w1=w;h1=h; | 
|  |  | w1=grd_curscreen->sc_w;h1=grd_curscreen->sc_h; | 
|  |  | if (ogl_readpixels_ok){ | 
|  |  | OGL_DISABLE(TEXTURE_2D); | 
|  |  | glReadBuffer(GL_FRONT); | 
|  |  | glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,texbuf); | 
|  |  | //		glReadPixels(sx,grd_curscreen->sc_h-(sy+h),w,h,GL_RGB,GL_UNSIGNED_BYTE,texbuf); | 
|  |  | //		glReadPixels(sx,sy,w+sx,h+sy,GL_RGB,GL_UNSIGNED_BYTE,texbuf); | 
|  |  | }else | 
|  |  | memset(texbuf,0,w1*h1*3); | 
|  |  | //gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize | 
|  |  | gr_init_bitmap(&tmp,BM_LINEAR,0,0,w1,h1,w1,data); | 
|  |  | d=data; | 
|  |  | for (i=0;i<h1;i++){ | 
|  |  | s=texbuf+(h1-(i+1))*w1*3; | 
|  |  | for (j=0;j<w1;j++){ | 
|  |  | *d=gr_find_closest_color(s[0]/4,s[1]/4,s[2]/4); | 
|  |  | s+=3; | 
|  |  | d++; | 
|  |  | } | 
|  |  | } | 
| sx+=src->bm_x; |  | sx+=src->bm_x; | 
| sy+=src->bm_y; |  | sy+=src->bm_y; | 
| #if 0//also seems to cause a mess.  need to look into it a bit more.. |  | gr_bm_ubitbltm(w,h,dx,dy,sx,sy,&tmp,dest); | 
|  |  | //	gr_bm_ubitbltm(w,h,dx,dy,0,0,&tmp,dest); | 
|  |  | #else | 
|  |  | int i,j,c=0; | 
|  |  | unsigned char *d,*s,*e; | 
|  |  | sx+=src->bm_x; | 
|  |  | sy+=src->bm_y; | 
|  |  | #if 1//also seems to cause a mess.  need to look into it a bit more.. | 
| if (ogl_readpixels_ok){ |  | if (ogl_readpixels_ok){ | 
| OGL_DISABLE(TEXTURE_2D); |  | OGL_DISABLE(TEXTURE_2D); | 
| glReadBuffer(GL_FRONT); |  | glReadBuffer(GL_FRONT); | 
|  |  |  | 
| }else |  | }else | 
| #endif |  | #endif | 
| memset(texbuf,0,w*h*3); |  | memset(texbuf,0,w*h*3); | 
|  |  | //	d=dest->bm_data+dx+(dy+i)*dest->bm_rowsize; | 
|  |  | d=dest->bm_data+dx+dy*dest->bm_rowsize; | 
| for (i=0;i<h;i++){ |  | for (i=0;i<h;i++){ | 
| s=texbuf+w*(h-(i+1))*3; |  | s=texbuf+w*(h-(i+1))*3; | 
| //		s=texbuf+w*i*3; |  | //		s=texbuf+w*i*3; | 
| if (s<texbuf){Error("blah1\n");} |  | if (s<texbuf){Error("blah1\n");} | 
| d=dest->bm_data+dx+(dy+i)*dest->bm_rowsize; |  |  | 
| if (d<dest->bm_data){Error("blah3\n");} |  | if (d<dest->bm_data){Error("blah3\n");} | 
| //		d=dest->bm_data+(i*dest->bm_rowsize); |  | //		d=dest->bm_data+(i*dest->bm_rowsize); | 
|  |  |  | 
|  |  | e=d; | 
| for (j=0;j<w;j++){ |  | for (j=0;j<w;j++){ | 
| if (s>texbuf+w*h*3-3){Error("blah2\n");} |  | if (s>texbuf+w*h*3-3){Error("blah2\n");} | 
| if (d>dest->bm_data+dest->bm_rowsize*h){Error("blah4\n");} |  | if (d>dest->bm_data+dest->bm_rowsize*(h+dy)+dx	){Error("blah4\n");} | 
| *d=gr_find_closest_color(s[0]/4,s[1]/4,s[2]/4); |  | *d=gr_find_closest_color(s[0]/4,s[1]/4,s[2]/4); | 
| s+=3; |  | s+=3; | 
| d++; |  | d++; | 
|  |  | c++; | 
| } |  | } | 
|  |  | d=e; | 
|  |  | d+=dest->bm_rowsize; | 
| } |  | } | 
|  |  | mprintf((0,"c=%i w*h=%i\n",c,w*h)); | 
|  |  | #endif | 
| return 0; |  | return 0; | 
| } |  | } | 
|  |  |  |