]> icculus.org git repositories - btb/d2x.git/blob - include/ogl_init.h
properly render cloaked walls in OpenGL (fixes #1608)
[btb/d2x.git] / include / ogl_init.h
1 //prototypes opengl functions - Added 9/15/99 Matthew Mueller
2 #ifndef _OGL_INIT_H_ 
3 #define _OGL_INIT_H_
4
5 #ifdef _MSC_VER
6 # undef MAC // dirty feckin hack
7 #include <windows.h>
8 #include <stddef.h>
9 # define MAC(x)
10 #endif
11
12 //#ifdef _WIN32
13 //#define OGL_RUNTIME_LOAD
14 //#endif
15
16 #ifdef OGL_RUNTIME_LOAD
17 #include "loadgl.h"
18 int ogl_init_load_library(void);
19 #else
20 #if defined(__APPLE__) && defined(__MACH__)
21 #include <OpenGL/gl.h>
22 #else
23 #include <GL/gl.h>
24 #endif
25 //######hack, since multi texture support is not working
26 #undef GL_ARB_multitexture
27 #undef GL_SGIS_multitexture
28 #endif
29
30 #ifndef GL_VERSION_1_1
31 #ifdef GL_EXT_texture
32 #define GL_INTENSITY4 GL_INTENSITY4_EXT
33 #define GL_INTENSITY8 GL_INTENSITY8_EXT
34 #endif
35 #endif
36
37
38 #include "gr.h"
39 #include "palette.h"
40 #include "pstypes.h"
41
42 /* I assume this ought to be >= MAX_BITMAP_FILES in piggy.h? */
43 #define OGL_TEXTURE_LIST_SIZE 3000
44
45 typedef struct _ogl_texture {
46         GLuint handle;
47         GLint internalformat;
48         GLenum format;
49         int w,h,tw,th,lw;
50         int bytesu;
51         int bytes;
52         GLfloat u,v;
53         GLfloat prio;
54         int wrapstate;
55         fix lastrend;
56         unsigned long numrend;
57         char wantmip;
58 } ogl_texture;
59
60 extern ogl_texture ogl_texture_list[OGL_TEXTURE_LIST_SIZE];
61
62 extern int ogl_mem_target;
63 ogl_texture* ogl_get_free_texture(void);
64 void ogl_init_texture(ogl_texture* t);
65 void ogl_init_texture_list_internal(void);
66 void ogl_smash_texture_list_internal(void);
67 void ogl_vivify_texture_list_internal(void);
68
69 extern int ogl_fullscreen;
70 void ogl_do_fullscreen_internal(void);
71
72 extern int ogl_voodoohack;
73
74 extern int ogl_alttexmerge;//merge textures by just printing the seperate textures?
75 extern int ogl_rgba_format;
76 extern int ogl_intensity4_ok;
77 extern int ogl_luminance4_alpha4_ok;
78 extern int ogl_rgba2_ok;
79 extern int ogl_readpixels_ok;
80 extern int ogl_gettexlevelparam_ok;
81 #ifdef GL_ARB_multitexture
82 extern int ogl_arb_multitexture_ok;
83 #else
84 #define ogl_arb_multitexture_ok 0
85 #endif
86 #ifdef GL_SGIS_multitexture
87 extern int ogl_sgis_multitexture_ok;
88 #else
89 #define ogl_sgis_multitexture_ok 0
90 #endif
91
92 extern int gl_initialized;
93 extern int GL_texmagfilt,GL_texminfilt,GL_needmipmaps;
94 extern int gl_reticle;
95
96 extern int GL_TEXTURE_2D_enabled;
97 //extern int GL_texclamp_enabled;
98 //extern int GL_TEXTURE_ENV_MODE_state,GL_TEXTURE_MAG_FILTER_state,GL_TEXTURE_MIN_FILTER_state;
99 #define OGL_ENABLE2(a,f) {if (a ## _enabled!=1) {f;a ## _enabled=1;}}
100 #define OGL_DISABLE2(a,f) {if (a ## _enabled!=0) {f;a ## _enabled=0;}}
101
102 //#define OGL_ENABLE(a) OGL_ENABLE2(a,glEnable(a))
103 //#define OGL_DISABLE(a) OGL_DISABLE2(a,glDisable(a))
104 #define OGL_ENABLE(a) OGL_ENABLE2(GL_ ## a,glEnable(GL_ ## a))
105 #define OGL_DISABLE(a) OGL_DISABLE2(GL_ ## a,glDisable(GL_ ## a))
106
107 //#define OGL_TEXCLAMP() OGL_ENABLE2(GL_texclamp,glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);)
108 //#define OGL_TEXREPEAT() OGL_DISABLE2(GL_texclamp,glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);)
109
110 //#define OGL_SETSTATE(a,s,f) {if (a ## _state!=s) {f;a ## _state=s;}}
111
112 //#define OGL_TEXENV(p,m) OGL_SETSTATE(p,m,glTexEnvi(GL_TEXTURE_ENV, p,m));
113 //#define OGL_TEXPARAM(p,m) OGL_SETSTATE(p,m,glTexParameteri(GL_TEXTURE_2D,p,m));
114
115 extern int last_width,last_height;
116 #define OGL_VIEWPORT(x,y,w,h){if (w!=last_width || h!=last_height){glViewport(x,grd_curscreen->sc_canvas.cv_bitmap.bm_h-y-h,w,h);last_width=w;last_height=h;}}
117
118 //platform specific funcs
119 //MSVC seems to have problems with inline funcs not being found during linking
120 #ifndef _MSC_VER
121 inline 
122 #endif
123 void ogl_swap_buffers_internal(void);
124 int ogl_check_mode(int x, int y); // check if mode is valid
125 int ogl_init_window(int x, int y);//create a window/switch modes/etc
126 void ogl_destroy_window(void);//destroy window/etc
127 void ogl_init(void);//one time initialization
128 void ogl_close(void);//one time shutdown
129
130 //generic funcs
131 //#define OGLTEXBUFSIZE (1024*1024*4)
132 #define OGLTEXBUFSIZE (2048*2048*4)
133 extern GLubyte texbuf[OGLTEXBUFSIZE];
134 //void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int width,int height,int twidth,int theight);
135 void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight,int type);
136 void ogl_loadbmtexture_m(grs_bitmap *bm,int domipmap);
137 void ogl_loadbmtexture(grs_bitmap *bm);
138 //void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,int dyo, int *texid,float *u,float *v,char domipmap,float prio);
139 void ogl_loadtexture(unsigned char * data, int dxo,int dyo, ogl_texture *tex);
140 void ogl_freetexture(ogl_texture *gltexture);
141 void ogl_freebmtexture(grs_bitmap *bm);
142 void ogl_do_palfx(void);
143 void ogl_start_frame(void);
144 void ogl_end_frame(void);
145 void ogl_swap_buffers(void);
146 void ogl_set_screen_mode(void);
147 void ogl_cache_level_textures(void);
148
149 void ogl_urect(int left,int top,int right,int bot);
150 bool ogl_ubitmapm_c(int x, int y,grs_bitmap *bm,int c);
151 bool ogl_ubitmapm(int x, int y,grs_bitmap *bm);
152 bool ogl_ubitblt_i(int dw,int dh,int dx,int dy, int sw, int sh, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
153 bool ogl_ubitblt(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
154 bool ogl_ubitblt_tolinear(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
155 bool ogl_ubitblt_copy(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
156 void ogl_upixelc(int x, int y, int c);
157 void ogl_ulinec(int left,int top,int right,int bot,int c);
158
159 extern unsigned char *ogl_pal;
160
161 #include "3d.h"
162 bool g3_draw_tmap_2(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bmbot,grs_bitmap *bm,int orient);
163
164 void ogl_draw_reticle(int cross,int primary,int secondary);
165
166 //whee
167 //#define PAL2Tr(c) ((gr_palette[c*3]+gr_palette_gamma)/63.0)
168 //#define PAL2Tg(c) ((gr_palette[c*3+1]+gr_palette_gamma)/63.0)
169 //#define PAL2Tb(c) ((gr_palette[c*3+2]+gr_palette_gamma)/63.0)
170 //#define PAL2Tr(c) ((gr_palette[c*3])/63.0)
171 //#define PAL2Tg(c) ((gr_palette[c*3+1])/63.0)
172 //#define PAL2Tb(c) ((gr_palette[c*3+2])/63.0)
173 #define CPAL2Tr(c) ((gr_current_pal[c*3])/63.0)
174 #define CPAL2Tg(c) ((gr_current_pal[c*3+1])/63.0)
175 #define CPAL2Tb(c) ((gr_current_pal[c*3+2])/63.0)
176 #define PAL2Tr(c) ((ogl_pal[c*3])/63.0)
177 #define PAL2Tg(c) ((ogl_pal[c*3+1])/63.0)
178 #define PAL2Tb(c) ((ogl_pal[c*3+2])/63.0)
179 //inline GLfloat PAL2Tr(int c);
180 //inline GLfloat PAL2Tg(int c);
181 //inline GLfloat PAL2Tb(int c);
182
183 #endif