Skip to content

Commit 491f581

Browse files
committed
Import some missing functions
Originally from https://github.com/erysdren/TinyGL
1 parent ab7331c commit 491f581

19 files changed

+1874
-739
lines changed

GL/gl.h

+631-622
Large diffs are not rendered by default.

GL/glu.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "gl.h"
3+
4+
void gluPerspective(GLdouble fovy, GLdouble aspect,
5+
GLdouble zNear, GLdouble zFar);
6+
7+
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
8+
GLdouble centerx, GLdouble centery, GLdouble centerz,
9+
GLdouble upx, GLdouble upy, GLdouble upz);
10+
11+
typedef struct
12+
{
13+
int draw_style;
14+
} GLUquadricObj;
15+
16+
#define GLU_LINE 0
17+
18+
GLUquadricObj *gluNewQuadric(void);
19+
void gluQuadricDrawStyle(GLUquadricObj *obj, int style);
20+
21+
void gluSphere(GLUquadricObj *qobj,
22+
float radius,int slices,int stacks);
23+
void gluCylinder(GLUquadricObj *qobj,
24+
GLdouble baseRadius, GLdouble topRadius, GLdouble height,
25+
GLint slices, GLint stacks);
26+
void gluDisk(GLUquadricObj *qobj,
27+
GLdouble innerRadius, GLdouble outerRadius,
28+
GLint slices, GLint loops);
29+
30+
void drawTorus(float rc, int numc, float rt, int numt);

GL/ostinygl.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/* guard */
3+
#ifndef _tgl_osbuffer_h_
4+
#define _tgl_osbuffer_h_
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
/* struct type */
10+
typedef struct
11+
{
12+
void *zb; /* private ZBuffer struct */
13+
void *pixels; /* read-write pixel buffer */
14+
unsigned char *palette; /* 768 bytes of RGB color data if depth == 8 */
15+
int width, height; /* width, height */
16+
int depth; /* bpp */
17+
} ostgl_context_t;
18+
19+
/* functions */
20+
21+
/* create context. valid bits per pixel are 8, 16, 24, and 32. */
22+
ostgl_context_t *ostgl_create_context(int width, int height, int depth);
23+
24+
/* if you have multiple contexts, call this to make one "current" */
25+
void ostgl_make_current(ostgl_context_t *context);
26+
27+
/* delete context and free all associated memory */
28+
void ostgl_delete_context(ostgl_context_t *context);
29+
30+
/* resize framebuffer to specified with and height */
31+
void ostgl_resize(ostgl_context_t *context, int width, int height);
32+
33+
/* convert framebuffer to specified bpp */
34+
/* you only need to call this function if your target bits-per-pixel != 16. */
35+
void *ostgl_convert_framebuffer(ostgl_context_t *context);
36+
37+
/* guard */
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
#endif /* _tgl_osbuffer_h_ */

api.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void glViewport(int x,int y,int width,int height)
352352
}
353353

354354
void glFrustum(double left,double right,double bottom,double top,
355-
double near,double farv)
355+
double nearv,double farv)
356356
{
357357
GLParam p[7];
358358

@@ -361,12 +361,28 @@ void glFrustum(double left,double right,double bottom,double top,
361361
p[2].f=right;
362362
p[3].f=bottom;
363363
p[4].f=top;
364-
p[5].f=near;
364+
p[5].f=nearv;
365365
p[6].f=farv;
366366

367367
gl_add_op(p);
368368
}
369369

370+
void glOrtho(double left, double right, double bottom, double top,
371+
double nearv, double farv)
372+
{
373+
GLParam p[7];
374+
375+
p[0].op = OP_Ortho;
376+
p[1].f = left;
377+
p[2].f = right;
378+
p[3].f = bottom;
379+
p[4].f = top;
380+
p[5].f = nearv;
381+
p[6].f = farv;
382+
383+
gl_add_op(p);
384+
}
385+
370386
/* lightening */
371387

372388
void glMaterialfv(int mode,int type,float *v)

arrays.c

+128
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,131 @@ glTexCoordPointer(GLint size, GLenum type, GLsizei stride,
206206
p[3].p = (void*)pointer;
207207
gl_add_op(p);
208208
}
209+
210+
/*
211+
* erysdren
212+
*/
213+
214+
void glopDrawElements(GLContext *c, GLParam *p)
215+
{
216+
/* variables */
217+
GLenum mode = p[1].i;
218+
GLsizei count = p[2].i;
219+
GLenum type = p[3].i;
220+
GLvoid *indices = p[4].p;
221+
int i;
222+
GLParam param_ptr[2];
223+
GLParam param_mode[2];
224+
225+
/* setup params */
226+
param_ptr[0].op = OP_ArrayElement;
227+
228+
param_mode[0].op = OP_Begin;
229+
param_mode[1].i = mode;
230+
231+
/* type */
232+
switch (type)
233+
{
234+
/* uint8 */
235+
case GL_UNSIGNED_BYTE:
236+
{
237+
glopBegin(c, param_mode);
238+
for (i = 0; i < count; i++)
239+
{
240+
param_ptr[1].i = (GLint)((GLubyte *)indices)[i];
241+
glopArrayElement(c, param_ptr);
242+
}
243+
glopEnd(c, NULL);
244+
break;
245+
}
246+
247+
/* uint16 */
248+
case GL_UNSIGNED_SHORT:
249+
{
250+
glopBegin(c, param_mode);
251+
for (i = 0; i < count; i++)
252+
{
253+
param_ptr[1].i = (GLint)((GLushort *)indices)[i];
254+
glopArrayElement(c, param_ptr);
255+
}
256+
glopEnd(c, NULL);
257+
break;
258+
}
259+
260+
/* uint32 */
261+
case GL_UNSIGNED_INT:
262+
{
263+
glopBegin(c, param_mode);
264+
for (i = 0; i < count; i++)
265+
{
266+
param_ptr[1].i = (GLint)((GLuint *)indices)[i];
267+
glopArrayElement(c, param_ptr);
268+
}
269+
glopEnd(c, NULL);
270+
break;
271+
}
272+
273+
default:
274+
{
275+
gl_fatal_error("glDrawElements with invalid type!");
276+
break;
277+
}
278+
}
279+
}
280+
281+
void glDrawElements(GLenum mode, GLsizei count, GLenum type,
282+
const GLvoid *indices)
283+
{
284+
GLParam p[5];
285+
286+
p[0].op = OP_DrawElements;
287+
p[1].i = mode;
288+
p[2].i = count;
289+
p[3].i = type;
290+
p[4].p = (void *)indices;
291+
292+
gl_add_op(p);
293+
}
294+
295+
/* probably a hack */
296+
/* mesa's version of this function is way more complex */
297+
void glopDrawArrays(GLContext *c, GLParam *p)
298+
{
299+
/* variables */
300+
int i;
301+
GLenum mode = p[1].i;
302+
GLint first = p[2].i;
303+
GLsizei count = p[3].i;
304+
GLParam param_element[2];
305+
GLParam param_begin[2];
306+
307+
param_begin[0].op = OP_Begin;
308+
param_begin[1].i = mode;
309+
310+
param_element[0].op = OP_ArrayElement;
311+
312+
/* begin */
313+
glopBegin(c, param_begin);
314+
315+
/* do elements */
316+
for (i = 0; i < count; i++)
317+
{
318+
param_element[1].i = first + i;
319+
glopArrayElement(c, param_element);
320+
}
321+
322+
/* end */
323+
glopEnd(c, NULL);
324+
}
325+
326+
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
327+
{
328+
GLParam p[4];
329+
330+
p[0].op = OP_DrawArrays;
331+
p[1].i = mode;
332+
p[2].i = first;
333+
p[3].i = count;
334+
335+
gl_add_op(p);
336+
}

0 commit comments

Comments
 (0)