Merge branch 'master' of ssh://repo.or.cz/srv/git/tgl
[tgl.git] / src / init.c
blob6c3844994954ce794d44a463d52181763c8991e0
1 #include "zgl.h"
3 GLContext *gl_ctx;
6 void initSharedState(GLContext *c)
8 GLSharedState *s=&c->shared_state;
9 s->lists=gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS);
10 s->texture_hash_table=
11 gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE);
13 alloc_texture(c,0);
16 void endSharedState(GLContext *c)
18 GLSharedState *s=&c->shared_state;
19 int i;
21 for(i=0;i<MAX_DISPLAY_LISTS;i++) {
22 /* TODO */
24 gl_free(s->lists);
26 gl_free(s->texture_hash_table);
30 void glInit(void *zbuffer1)
32 ZBuffer *zbuffer=(ZBuffer *)zbuffer1;
33 GLContext *c;
34 GLViewport *v;
35 int i;
37 c=gl_zalloc(sizeof(GLContext));
38 gl_ctx=c;
40 c->zb=zbuffer;
42 /* allocate GLVertex array */
43 c->vertex_max = POLYGON_MAX_VERTEX;
44 c->vertex = gl_malloc(POLYGON_MAX_VERTEX*sizeof(GLVertex));
46 /* viewport */
47 v=&c->viewport;
48 v->xmin=0;
49 v->ymin=0;
50 v->xsize=zbuffer->xsize;
51 v->ysize=zbuffer->ysize;
52 v->updated=1;
54 /* shared state */
55 initSharedState(c);
57 /* lists */
59 c->exec_flag=1;
60 c->compile_flag=0;
61 c->print_flag=0;
63 c->in_begin=0;
65 /* lights */
66 for(i=0;i<MAX_LIGHTS;i++) {
67 GLLight *l=&c->lights[i];
68 l->ambient=gl_V4_New(0,0,0,1);
69 l->diffuse=gl_V4_New(1,1,1,1);
70 l->specular=gl_V4_New(1,1,1,1);
71 l->position=gl_V4_New(0,0,1,0);
72 l->norm_position=gl_V3_New(0,0,1);
73 l->spot_direction=gl_V3_New(0,0,-1);
74 l->norm_spot_direction=gl_V3_New(0,0,-1);
75 l->spot_exponent=0;
76 l->spot_cutoff=180;
77 l->attenuation[0]=1;
78 l->attenuation[1]=0;
79 l->attenuation[2]=0;
80 l->enabled=0;
82 c->first_light=NULL;
83 c->ambient_light_model=gl_V4_New(0.2,0.2,0.2,1);
84 c->local_light_model=0;
85 c->lighting_enabled=0;
86 c->light_model_two_side = 0;
88 /* default materials */
89 for(i=0;i<2;i++) {
90 GLMaterial *m=&c->materials[i];
91 m->emission=gl_V4_New(0,0,0,1);
92 m->ambient=gl_V4_New(0.2,0.2,0.2,1);
93 m->diffuse=gl_V4_New(0.8,0.8,0.8,1);
94 m->specular=gl_V4_New(0,0,0,1);
95 m->shininess=0;
97 c->current_color_material_mode=GL_FRONT_AND_BACK;
98 c->current_color_material_type=GL_AMBIENT_AND_DIFFUSE;
99 c->color_material_enabled=0;
101 /* textures */
102 glInitTextures(c);
104 /* default state */
105 c->current_color.X=1.0;
106 c->current_color.Y=1.0;
107 c->current_color.Z=1.0;
108 c->current_color.W=1.0;
109 c->longcurrent_color[0] = 65535;
110 c->longcurrent_color[1] = 65535;
111 c->longcurrent_color[2] = 65535;
113 c->current_normal.X=1.0;
114 c->current_normal.Y=0.0;
115 c->current_normal.Z=0.0;
116 c->current_normal.W=0.0;
118 c->current_edge_flag=1;
120 c->current_tex_coord.X=0;
121 c->current_tex_coord.Y=0;
122 c->current_tex_coord.Z=0;
123 c->current_tex_coord.W=1;
125 c->polygon_mode_front=GL_FILL;
126 c->polygon_mode_back=GL_FILL;
128 c->current_front_face=0; /* 0 = GL_CCW 1 = GL_CW */
129 c->current_cull_face=GL_BACK;
130 c->current_shade_model=GL_SMOOTH;
131 c->cull_face_enabled=0;
133 /* clear */
134 c->clear_color.v[0]=0;
135 c->clear_color.v[1]=0;
136 c->clear_color.v[2]=0;
137 c->clear_color.v[3]=0;
138 c->clear_depth=0;
140 /* selection */
141 c->render_mode=GL_RENDER;
142 c->select_buffer=NULL;
143 c->name_stack_size=0;
145 /* matrix */
146 c->matrix_mode=0;
148 c->matrix_stack_depth_max[0]=MAX_MODELVIEW_STACK_DEPTH;
149 c->matrix_stack_depth_max[1]=MAX_PROJECTION_STACK_DEPTH;
150 c->matrix_stack_depth_max[2]=MAX_TEXTURE_STACK_DEPTH;
152 for(i=0;i<3;i++) {
153 c->matrix_stack[i]=gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(M4));
154 c->matrix_stack_ptr[i]=c->matrix_stack[i];
157 glMatrixMode(GL_PROJECTION);
158 glLoadIdentity();
159 glMatrixMode(GL_TEXTURE);
160 glLoadIdentity();
161 glMatrixMode(GL_MODELVIEW);
162 glLoadIdentity();
164 c->matrix_model_projection_updated=1;
166 /* opengl 1.1 arrays */
167 c->client_states = 0;
169 /* opengl 1.1 polygon offset */
170 c->offset_states = 0;
172 /* clear the resize callback function pointer */
173 c->gl_resize_viewport = NULL;
175 /* specular buffer */
176 c->specbuf_first = NULL;
177 c->specbuf_used_counter = 0;
178 c->specbuf_num_buffers = 0;
180 /* depth test */
181 c->depth_test = 0;
184 void glClose(void)
186 GLContext *c=gl_get_context();
187 endSharedState(c);
188 gl_free(c);