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