Permalink
Browse files

Removed part gluttess example and added debug printouts.

  • Loading branch information...
dgud committed May 20, 2009
1 parent a5f6ead commit b8049326a0c097d22783442904c6558e529fe656
Showing with 50 additions and 32 deletions.
  1. +46 −17 c_src/esdl_glu.c
  2. +4 −15 test/testglutess.erl
View
@@ -64,13 +64,16 @@ typedef struct _tessobj {
void CALLBACK esdl_nop_callback(GLboolean flag)
{
+/* fprintf(stderr, "NOOP: \r\n"); */
+/* fflush(stderr); */
}
void CALLBACK errorCallback(GLenum errorCode)
{
const GLubyte *err;
err = gluErrorString(errorCode);
- fprintf(stderr, "Tesselation error: %d: %s\r\n", (int)errorCode, err);
+/* fprintf(stderr, "Tesselation error: %d: %s\r\n", (int)errorCode, err); */
+/* fflush(stderr); */
}
void CALLBACK esdl_combine(GLdouble coords[3],
@@ -88,6 +91,9 @@ void CALLBACK esdl_combine(GLdouble coords[3],
unsigned char* datap[4] = {NULL, NULL, NULL, NULL};
unsigned flags;
+/* fprintf(stderr, "Combine: %d\r\n", (int) eobj); */
+/* fflush(stderr); */
+
flags = ((unsigned char *)vertex_data[0])[-1];
for (max = 0; max < 4 && vertex_data[max] != NULL; max++) {
if (((unsigned char *)vertex_data[max])[-1] != flags) {
@@ -106,7 +112,7 @@ void CALLBACK esdl_combine(GLdouble coords[3],
size += 3*4;
}
if (flags & ESDL_TESS_VTXDATA_COLOR) {
- size += 2*4;
+ size += 4*4;
}
mycoords = (eglu_tessdata*) malloc(sizeof(GLdouble) +
@@ -131,7 +137,8 @@ esdl_udata_vertex(GLdouble* coords)
GLfloat* datap = (GLfloat *) (coords+3);
unsigned flags = ((unsigned char *) coords)[-1];
- /* fprintf(stderr, "Flags: %d\r\n", flags); */
+/* fprintf(stderr, "Flags: %d ", flags); */
+/* fflush(stderr); */
if (flags & ESDL_TESS_VTXDATA_MATERIAL) {
GLenum face = ((unsigned short *) datap)[0];
GLenum pname = ((unsigned short *) datap)[1];
@@ -152,10 +159,10 @@ esdl_udata_vertex(GLdouble* coords)
datap += 4;
}
glVertex3dv(coords);
+/* fprintf(stderr, "EFlags: %d\r\n", flags); */
+/* fflush(stderr); */
}
-
-
void eglu_newTess (sdl_data *sd, int len, char * buff)
{
char *bp, *start;
@@ -164,12 +171,18 @@ void eglu_newTess (sdl_data *sd, int len, char * buff)
eglu_tessobj * eobj;
tobj = gluNewTess();
+ gluTessCallback(tobj, GLU_TESS_EDGE_FLAG,
+ (GLvoid (CALLBACK *)()) esdl_nop_callback);
+ gluTessCallback(tobj, GLU_TESS_ERROR,
+ (GLvoid (CALLBACK *)()) errorCallback);
+
eobj = (eglu_tessobj *) malloc(sizeof(eglu_tessobj));
eobj->tess = tobj;
eobj->data = NULL;
eobj->freep = eobj->def_heap;
-/* fprintf(stderr, "New tess: %d -> %d \r\n", (int) eobj, (int) tobj); */
+/* fprintf(stderr, "New tess: %d -> %d \r\n", (int) eobj, (int) tobj); */
+/* fflush(stderr); */
/*
* Send back result.
@@ -190,7 +203,8 @@ void eglu_deleteTess (sdl_data *sd, int len, char * buff)
POPGLPTR(eobj, bp);
gluDeleteTess(eobj->tess);
free(eobj);
-/* fprintf(stderr, "Deleting tess: %d\r\n", (int) eobj); */
+/* fprintf(stderr, "Deleting tess: %d\r\n", (int) eobj); */
+/* fflush(stderr); */
}
void eglu_tessBeginPolygon (sdl_data *sd, int len, char* bp)
@@ -211,6 +225,9 @@ void eglu_tessVertex(sdl_data *sd, int len, char* bp)
char* extrap;
POPGLPTR(eobj, bp);
+/* fprintf(stderr, "tessVertex: %d", (int) eobj); */
+/* fflush(stderr); */
+
size = len - 8;
nbytes = sizeof(GLdouble) + sizeof(eglu_tessdata) + size;
ndoubles = (nbytes-1)/sizeof(GLdouble) + 1;
@@ -229,9 +246,10 @@ void eglu_tessVertex(sdl_data *sd, int len, char* bp)
} else {
extrap[-1] = 0;
}
-/* fprintf(stderr, "tessVertex: %d %g %g %g\r\n", */
-/* (int) eobj, coords->data[0], coords->data[1], coords->data[2]); */
- gluTessVertex(eobj->tess, coords->data+1, coords->data+1);
+/* fprintf(stderr, "tessVertex: %d %g %g %g\r\n", */
+/* (int) eobj, coords->data[0], coords->data[1], coords->data[2]); */
+/* fflush(stderr); */
+ gluTessVertex(eobj->tess, coords->data+1, coords->data+1);
}
void eglu_tessEndPolygon (sdl_data *sd, int len, char * buff)
@@ -242,7 +260,13 @@ void eglu_tessEndPolygon (sdl_data *sd, int len, char * buff)
bp = buff;
POPGLPTR(eobj, bp);
+/* fprintf(stderr, "End Polygon: %d\r\n", (int) eobj); */
+/* fflush(stderr); */
+
gluTessEndPolygon(eobj->tess);
+/* fprintf(stderr, "End Polygon: %d\r\n", (int) eobj); */
+/* fflush(stderr); */
+
remove = eobj->data;
while (remove != NULL) {
temp = remove->next;
@@ -252,8 +276,8 @@ void eglu_tessEndPolygon (sdl_data *sd, int len, char * buff)
eobj->data = NULL;
eobj->freep = eobj->def_heap;
-/* fprintf(stderr, "End Polygon: %d\r\n", (int) eobj); */
-
+/* fprintf(stderr, "End Polygon: %d\r\n", (int) eobj); */
+/* fflush(stderr); */
}
void eglu_tessCallback(sdl_data *sd, int len, char * buff)
@@ -309,7 +333,8 @@ void eglu_tessCallback(sdl_data *sd, int len, char * buff)
break;
};
gluTessCallback(eobj->tess, *which, cbfn);
-/* fprintf(stderr, "Tess Callback: %d %d\r\n", (int) eobj, *cbId); */
+/* fprintf(stderr, "Tess Callback: %d %d\r\n", (int) eobj, cbId); */
+/* fflush(stderr); */
}
void eglu_beginCurve(sdl_data *egl_sd, int egl_len, char *egl_buff)
{
@@ -318,7 +343,6 @@ void eglu_beginCurve(sdl_data *egl_sd, int egl_len, char *egl_buff)
bp = egl_buff;
POPGLPTR(nurb,bp);
gluBeginCurve(nurb);
-
}
void eglu_beginSurface(sdl_data *egl_sd, int egl_len, char *egl_buff)
@@ -858,6 +882,8 @@ void eglu_tessBeginContour(sdl_data *egl_sd, int egl_len, char *egl_buff)
eglu_tessobj * tess;
bp = egl_buff;
POPGLPTR(tess, bp);
+/* fprintf(stderr, "Begin Contour: %d\r\n", (int) tess); */
+/* fflush(stderr); */
gluTessBeginContour(tess->tess);
}
@@ -868,7 +894,8 @@ void eglu_tessEndContour(sdl_data *egl_sd, int egl_len, char *egl_buff)
bp = egl_buff;
POPGLPTR(tess, bp);
gluTessEndContour(tess->tess);
-/* fprintf(stderr, "Begin Contour: %d\r\n", (int) tess); */
+/* fprintf(stderr, "End Contour: %d\r\n", (int) tess); */
+/* fflush(stderr); */
}
@@ -945,7 +972,8 @@ esdl_etess_error(GLenum errorCode)
{
const GLubyte *err;
err = gluErrorString(errorCode);
- fprintf(stderr, "Tesselation error: %d: %s\r\n", (int)errorCode, err);
+/* fprintf(stderr, "Tesselation error: %d: %s\r\n", (int)errorCode, err); */
+/* fflush(stderr); */
}
void CALLBACK
@@ -1048,7 +1076,8 @@ void esdl_triangulate(sdl_data *sd, int count, char* buff)
* the the list of vertex indices.
*/
new_sz = (etess_alloc_vertex - new_vertices)*sizeof(GLdouble);
- bin_sz = ((char *)etess_vertices) - ((char *)((ErlDrvBinary *)sd->buff)->orig_bytes);
+ bin_sz = ((char *)etess_vertices) -
+ ((char *)((ErlDrvBinary *)sd->buff)->orig_bytes);
sd->buff = driver_realloc_binary(sd->buff, bin_sz + new_sz);
sd->len = bin_sz + new_sz;
etess_vertices = (int *) (((ErlDrvBinary *)sd->buff)->orig_bytes + bin_sz);
View
@@ -21,6 +21,9 @@
-include("glu.hrl").
-export([go/0, go/1, drawBox/2]).
+-compile(export_all).
+init() ->
+ sdl:init(?SDL_INIT_VIDEO bor ?SDL_INIT_ERLDRIVER bor ?SDL_INIT_NOPARACHUTE).
go() ->
go([]).
@@ -34,6 +37,7 @@ go(Config) ->
sdl_events:eventState(?SDL_KEYDOWN ,?SDL_ENABLE),
sdl_events:eventState(?SDL_QUIT ,?SDL_ENABLE),
initWin(),
+ test_triangulate(),
Cube = [{ 1, 1, -0.5},
{ 0.5, 0, -0.5},
@@ -48,7 +52,6 @@ go(Config) ->
{Time, N} = timer:tc(?MODULE, drawBox, [Cube, 0]),
erlang:display(N),
Secs = Time / 1000000,
- test_triangulate(),
sdl:quit(),
erlang:display(round(N/Secs)),
N.
@@ -76,28 +79,14 @@ drawBox(Cube, N) ->
glu:tessCallback(Tess, ?GLU_TESS_VERTEX_DATA, ?ESDL_TESSCB_VERTEX_DATA),
glu:tessCallback(Tess, ?GLU_TESS_ERROR, ?ESDL_TESSCB_ERROR_PRINT),
glu:tessCallback(Tess, ?GLU_TESS_COMBINE, ?ESDL_TESSCB_COMBINE),
-
glu:tessBeginPolygon(Tess),
glu:tessBeginContour(Tess),
glu:tessNormal(Tess, 0, 0, -1),
lists:foreach(fun(V) -> glu:tessVertex(Tess, V, [{color, myabs(V)}]) end, Cube),
glu:tessEndContour(Tess),
glu:tessEndPolygon(Tess),
-
gl:disable(?GL_DEPTH_TEST),
-
gl:color3f(1,0,0),
- glu:tessProperty(Tess, ?GLU_TESS_BOUNDARY_ONLY, ?GL_TRUE),
- glu:tessBeginPolygon(Tess),
- glu:tessBeginContour(Tess),
- glu:tessNormal(Tess, 0, 0, -1),
- lists:foreach(fun(V) -> glu:tessVertex(Tess, V) end, Cube),
- glu:tessEndContour(Tess),
- glu:tessEndPolygon(Tess),
-
- ?GL_TRUE = round(glu:getTessProperty(Tess, ?GLU_TESS_BOUNDARY_ONLY)),
- glu:deleteTess(Tess),
-
%% timer:sleep(200),
case {gl:getError(), sdl:getError()} of
{0, ""} ->

0 comments on commit b804932

Please sign in to comment.