summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorscuri <scuri>2010-06-24 19:16:35 +0000
committerscuri <scuri>2010-06-24 19:16:35 +0000
commitda0f58cecf7a5280df7efa4e8d4443cb65b0fe1d (patch)
treed218429e378e665654db9a41e103e50f727e3e5e /src
parent57d27736fe65aa25f8c03c790c11475cc06d1296 (diff)
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/cdluagl3.mak15
-rw-r--r--src/cdluagl5.mak23
-rw-r--r--src/drv/cdgl.c242
-rw-r--r--src/lua3/cdluagl.c43
-rw-r--r--src/lua3/cdluagl.def2
-rw-r--r--src/lua5/cdluagl5.c53
-rw-r--r--src/lua5/cdluagl5.def3
-rw-r--r--src/sim/sim_primitives.c2
8 files changed, 305 insertions, 78 deletions
diff --git a/src/cdluagl3.mak b/src/cdluagl3.mak
new file mode 100644
index 0000000..e655afd
--- /dev/null
+++ b/src/cdluagl3.mak
@@ -0,0 +1,15 @@
+PROJNAME = cd
+LIBNAME = cdluagl3
+
+OPT = YES
+
+DEF_FILE = cdluagl.def
+SRCDIR = lua3
+SRC = cdluagl.c
+DEF_FILE = cdluagl.def
+
+INCLUDES = ../include
+LIBS = cdlua3 cdgl
+LDIR = ../lib/$(TEC_UNAME)
+
+USE_LUA = YES
diff --git a/src/cdluagl5.mak b/src/cdluagl5.mak
new file mode 100644
index 0000000..a9077bc
--- /dev/null
+++ b/src/cdluagl5.mak
@@ -0,0 +1,23 @@
+PROJNAME = cd
+LIBNAME = cdluagl
+
+OPT = YES
+
+DEFINES = CD_NO_OLD_INTERFACE
+SRCDIR = lua5
+SRC = cdluagl5.c
+DEF_FILE = cdluagl5.def
+
+LIBS = cdgl
+
+ifdef USE_LUA52
+ LIBNAME := $(LIBNAME)52
+else
+ USE_LUA51 = Yes
+ LIBNAME := $(LIBNAME)51
+endif
+
+NO_LUALINK = Yes
+USE_CD = YES
+USE_CDLUA = YES
+CD = ..
diff --git a/src/drv/cdgl.c b/src/drv/cdgl.c
index c8f818a..2934684 100644
--- a/src/drv/cdgl.c
+++ b/src/drv/cdgl.c
@@ -16,7 +16,6 @@
#endif
#include <GL/gl.h>
-#include <GL/glu.h>
#include <FTGL/ftgl.h>
@@ -80,16 +79,21 @@ static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsig
#ifdef WIN32
{
wchar_t* toUnicode;
+ int wlen = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
+ if(!wlen)
+ return (char*)str;
- toUnicode = (wchar_t*)malloc((len+1) * sizeof(wchar_t));
- MultiByteToWideChar(CP_ACP, 0, str, len+1, toUnicode, (len+1));
+ toUnicode = (wchar_t*)calloc((wlen+1), sizeof(wchar_t));
+ MultiByteToWideChar(CP_ACP, 0, str, len, toUnicode, wlen);
+ toUnicode[wlen] = 0;
- len = WideCharToMultiByte(CP_UTF8, 0, toUnicode, -1, NULL, 0, NULL, NULL);
+ len = WideCharToMultiByte(CP_UTF8, 0, toUnicode, wlen, NULL, 0, NULL, NULL);
if(!len)
return (char*)str;
- ctxcanvas->glLastConvertUTF8 = (char*)malloc(len * sizeof(char));
- WideCharToMultiByte(CP_UTF8, 0, toUnicode, -1, ctxcanvas->glLastConvertUTF8, len, NULL, NULL);
+ ctxcanvas->glLastConvertUTF8 = (char*)calloc((len+1), sizeof(char));
+ WideCharToMultiByte(CP_UTF8, 0, toUnicode, wlen, ctxcanvas->glLastConvertUTF8, len, NULL, NULL);
+ ctxcanvas->glLastConvertUTF8[len] = 0;
free(toUnicode);
}
@@ -184,24 +188,22 @@ static void cdcliparea(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int
static int cdwritemode(cdCtxCanvas *ctxcanvas, int write_mode)
{
- if(glIsEnabled(GL_COLOR_LOGIC_OP))
- glDisable(GL_COLOR_LOGIC_OP);
-
switch (write_mode)
{
case CD_REPLACE:
- glLogicOp(GL_COPY);
+ if(glIsEnabled(GL_COLOR_LOGIC_OP))
+ glDisable(GL_COLOR_LOGIC_OP);
break;
case CD_XOR:
+ glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
break;
case CD_NOT_XOR:
+ glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_EQUIV);
break;
}
- glEnable(GL_COLOR_LOGIC_OP);
-
(void)ctxcanvas;
return write_mode;
}
@@ -228,36 +230,6 @@ static int cdhatch(cdCtxCanvas *ctxcanvas, int hatch_style)
return hatch_style;
}
-static void cdglEnableBackOpacity(cdCtxCanvas* ctxcanvas)
-{
- if (ctxcanvas->canvas->back_opacity == CD_OPAQUE)
- {
- glColor4ub(cdRed(ctxcanvas->canvas->foreground),
- cdGreen(ctxcanvas->canvas->foreground),
- cdBlue(ctxcanvas->canvas->foreground), 255);
-
- glDepthMask(GL_TRUE);
-
- if(glIsEnabled(GL_DEPTH_TEST))
- glDisable(GL_DEPTH_TEST);
-
- if(glIsEnabled(GL_BLEND))
- glDisable(GL_BLEND);
- }
- else
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glEnable(GL_DEPTH_TEST);
- glDepthMask(GL_FALSE);
-
- glColor4ub(cdRed(ctxcanvas->canvas->foreground),
- cdGreen(ctxcanvas->canvas->foreground),
- cdBlue(ctxcanvas->canvas->foreground), 0);
- }
-}
-
static int cdinteriorstyle(cdCtxCanvas *ctxcanvas, int style)
{
switch (style)
@@ -275,18 +247,16 @@ static int cdinteriorstyle(cdCtxCanvas *ctxcanvas, int style)
switch (style)
{
+ case CD_STIPPLE:
+ case CD_PATTERN:
case CD_HOLLOW:
case CD_SOLID:
if(glIsEnabled(GL_POLYGON_STIPPLE))
glDisable(GL_POLYGON_STIPPLE);
break;
case CD_HATCH:
- cdglEnableBackOpacity(ctxcanvas);
cdhatch(ctxcanvas, ctxcanvas->canvas->hatch_style);
break;
- case CD_STIPPLE:
- case CD_PATTERN:
- break;
}
return style;
@@ -307,7 +277,6 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
case CD_DASH_DOT_DOT:
case CD_CUSTOM:
glEnable(GL_LINE_STIPPLE);
- cdglEnableBackOpacity(ctxcanvas);
break;
}
@@ -326,7 +295,7 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style)
glLineStipple(1, 0x333F);
break;
case CD_CUSTOM:
- /* style patterns more than 16 bits are not completely drawed */
+ /* style patterns more than 16 bits are not drawn completely */
glLineStipple(1, (GLushort)*ctxcanvas->canvas->line_dashes);
break;
}
@@ -591,12 +560,8 @@ static long int cdforeground(cdCtxCanvas *ctxcanvas, long int color)
unsigned char r, g, b;
(void)ctxcanvas;
- //TODO
- if(glIsEnabled(GL_POLYGON_STIPPLE))
- glDisable(GL_POLYGON_STIPPLE);
-
cdDecodeColor(color, &r, &g, &b);
- glColor3ub(r, g, b);
+ glColor4ub(r, g, b, cdDecodeAlpha(color));
return color;
}
@@ -643,6 +608,23 @@ static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int yma
static void cdfbox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
{
+ if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
+ {
+ /* draw twice, one with background color only, and one with foreground color */
+ glDisable(GL_POLYGON_STIPPLE);
+ glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background));
+
+ glBegin(GL_QUADS);
+ glVertex2d(xmin, ymin);
+ glVertex2d(xmax, ymin);
+ glVertex2d(xmax, ymax);
+ glVertex2d(xmin, ymax);
+ glEnd();
+
+ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground));
+ glEnable(GL_POLYGON_STIPPLE);
+ }
+
glBegin(GL_QUADS);
glVertex2d(xmin, ymin);
glVertex2d(xmax, ymin);
@@ -660,7 +642,7 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax
static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, int len)
{
- int dir = -1;
+ int dir = -1, stipple = 0;
float bounds[6];
int w, h, desc;
double x_origin = x;
@@ -733,20 +715,20 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i
cdfRotatePoint(ctxcanvas->canvas, x, y, x_origin, y_origin, &x, &y, sin_angle, cos_angle);
}
+ if(glIsEnabled(GL_POLYGON_STIPPLE))
+ {
+ stipple = 1;
+ glDisable(GL_POLYGON_STIPPLE);
+ }
+
glPushMatrix();
glTranslated(x, y, 0.0);
glRotated(ctxcanvas->canvas->text_orientation, 0, 0, 1);
-
- /* FTGL not operate as expected when a logical pixel operation (write mode) is enabled. */
- if(glIsEnabled(GL_COLOR_LOGIC_OP))
- {
- glDisable(GL_COLOR_LOGIC_OP);
- ftglRenderFont(ctxcanvas->font, s, FTGL_RENDER_ALL);
- glEnable(GL_COLOR_LOGIC_OP);
- }
- else
- ftglRenderFont(ctxcanvas->font, s, FTGL_RENDER_ALL);
+ ftglRenderFont(ctxcanvas->font, s, FTGL_RENDER_ALL);
glPopMatrix();
+
+ if(stipple)
+ glEnable(GL_POLYGON_STIPPLE);
}
static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
@@ -793,6 +775,7 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
glEvalMesh1(GL_LINE, 0, prec);
glDisable(GL_MAP1_VERTEX_3);
+ free(points);
return;
}
@@ -811,6 +794,21 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
glBegin(GL_LINE_STRIP);
break;
case CD_FILL :
+ if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
+ {
+ /* draw twice, one with background color only, and one with foreground color */
+ glDisable(GL_POLYGON_STIPPLE);
+ glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background));
+
+ glBegin(GL_POLYGON);
+ for(i = 0; i < n; i++)
+ glVertex2i(poly[i].x, poly[i].y);
+ glEnd();
+
+ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground));
+ glEnable(GL_POLYGON_STIPPLE);
+ }
+
glBegin(GL_POLYGON);
break;
}
@@ -847,6 +845,7 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
glEvalMesh1(GL_LINE, 0, prec);
glDisable(GL_MAP1_VERTEX_3);
+ free(points);
return;
}
@@ -865,6 +864,20 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
glBegin(GL_LINE_STRIP);
break;
case CD_FILL :
+ if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
+ {
+ glDisable(GL_POLYGON_STIPPLE);
+ glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background));
+
+ glBegin(GL_POLYGON);
+ for(i = 0; i < n; i++)
+ glVertex2d(poly[i].x, poly[i].y);
+ glEnd();
+
+ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground));
+ glEnable(GL_POLYGON_STIPPLE);
+ }
+
glBegin(GL_POLYGON);
break;
}
@@ -1022,6 +1035,7 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi
static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
/* Images are bitmaps, and cannot be directly rotated or scaled */
+ int blend = 1;
GLubyte* glImage;
int rw = xmax-xmin+1;
int rh = ymax-ymin+1;
@@ -1048,21 +1062,18 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns
if (w != rw || h != rh)
glPixelZoom((GLfloat)w/rw, (GLfloat)h/rh);
- glEnable(GL_BLEND);
+ if (!glIsEnabled(GL_BLEND))
+ {
+ blend = 0;
+ glEnable(GL_BLEND);
+ }
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glRasterPos2i(x, y);
+ glDrawPixels(rw, rh, GL_RGBA, GL_UNSIGNED_BYTE, glImage);
- if(glIsEnabled(GL_COLOR_LOGIC_OP))
- {
- glDisable(GL_COLOR_LOGIC_OP);
- glDrawPixels(rw, rh, GL_RGBA, GL_UNSIGNED_BYTE, glImage);
- glEnable(GL_COLOR_LOGIC_OP);
- }
- else
- glDrawPixels(rw, rh, GL_RGBA, GL_UNSIGNED_BYTE, glImage);
-
- glDisable(GL_BLEND);
+ if (!blend)
+ glDisable(GL_BLEND);
(void)ih;
(void)ctxcanvas;
@@ -1110,7 +1121,7 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
- glColor3ub(cdRed(color), cdGreen(color), cdBlue(color));
+ glColor4ub(cdRed(color), cdGreen(color), cdBlue(color), cdAlpha(color));
/* Draw pixel */
glPointSize(1);
@@ -1119,7 +1130,7 @@ static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
glEnd();
/* restore the foreground color */
- glColor3ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground));
+ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground));
(void)ctxcanvas;
}
@@ -1188,11 +1199,83 @@ static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix)
glLoadIdentity();
glMultMatrixd(&transformMTX[0][0]);
}
+ else
+ glLoadIdentity();
(void)ctxcanvas;
}
/******************************************************************/
+static void set_alpha_attrib(cdCtxCanvas* ctxcanvas, char* data)
+{
+ if (!data || data[0] == '0')
+ {
+ glDisable(GL_BLEND);
+ }
+ else
+ {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ (void)ctxcanvas;
+}
+
+static char* get_alpha_attrib(cdCtxCanvas* ctxcanvas)
+{
+ (void)ctxcanvas;
+
+ if (glIsEnabled(GL_BLEND))
+ return "1";
+ else
+ return "0";
+}
+
+static cdAttribute alpha_attrib =
+{
+ "ALPHA",
+ set_alpha_attrib,
+ get_alpha_attrib
+};
+
+static void set_aa_attrib(cdCtxCanvas* ctxcanvas, char* data)
+{
+ if (!data || data[0] == '0')
+ {
+ glDisable(GL_POINT_SMOOTH);
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_POLYGON_SMOOTH);
+ }
+ else
+ {
+ glEnable(GL_POINT_SMOOTH);
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POLYGON_SMOOTH);
+
+ glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+ glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+ glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+ }
+
+ (void)ctxcanvas;
+}
+
+static char* get_aa_attrib(cdCtxCanvas* ctxcanvas)
+{
+ (void)ctxcanvas;
+
+ if (glIsEnabled(GL_LINE_SMOOTH))
+ return "1";
+ else
+ return "0";
+}
+
+static cdAttribute aa_attrib =
+{
+ "ANTIALIAS",
+ set_aa_attrib,
+ get_aa_attrib
+};
static void set_poly_attrib(cdCtxCanvas *ctxcanvas, char* data)
{
@@ -1329,6 +1412,11 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data)
cdRegisterAttribute(canvas, &version_attrib);
cdRegisterAttribute(canvas, &poly_attrib);
cdRegisterAttribute(canvas, &size_attrib);
+ cdRegisterAttribute(canvas, &alpha_attrib);
+ cdRegisterAttribute(canvas, &aa_attrib);
+
+ cdCanvasSetAttribute(canvas, "ALPHA", "1");
+ cdCanvasSetAttribute(canvas, "ANTIALIAS", "1");
}
static void cdinittable(cdCanvas* canvas)
diff --git a/src/lua3/cdluagl.c b/src/lua3/cdluagl.c
new file mode 100644
index 0000000..408eadb
--- /dev/null
+++ b/src/lua3/cdluagl.c
@@ -0,0 +1,43 @@
+/** \file
+ * \brief GL Canvas Lua 3 Binding
+ *
+ * See Copyright Notice in cd.h
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "cd.h"
+#include "cdgl.h"
+
+#include <lua.h>
+#include <lauxlib.h>
+
+#include "cdlua.h"
+#include "cdluagl.h"
+#include "cdlua3_private.h"
+
+static void *cdgl_checkdata(int param)
+{
+ lua_Object data = lua_getparam(param);
+ if (!lua_isstring(data))
+ lua_error("cdCreateCanvas CD_GL: data should be of type string!");
+
+ return lua_getstring(data);
+}
+
+static cdContextLUA cdluaglctx =
+{
+ 0,
+ "CD_GL",
+ cdContextGL,
+ cdgl_checkdata,
+ NULL,
+ 0
+};
+
+void cdluagl_open(void)
+{
+ cdlua_addcontext(&cdluaglctx);
+}
+
diff --git a/src/lua3/cdluagl.def b/src/lua3/cdluagl.def
new file mode 100644
index 0000000..85639b9
--- /dev/null
+++ b/src/lua3/cdluagl.def
@@ -0,0 +1,2 @@
+EXPORTS
+ cdluagl_open \ No newline at end of file
diff --git a/src/lua5/cdluagl5.c b/src/lua5/cdluagl5.c
new file mode 100644
index 0000000..ad81730
--- /dev/null
+++ b/src/lua5/cdluagl5.c
@@ -0,0 +1,53 @@
+/** \file
+ * \brief OpenGL Canvas Lua 5 Binding
+ *
+ * See Copyright Notice in cd.h
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "cd.h"
+#include "cdgl.h"
+
+#include <lua.h>
+#include <lauxlib.h>
+
+#include "cdlua.h"
+#include "cdluagl.h"
+#include "cdlua5_private.h"
+
+
+static void *cdgl_checkdata(lua_State *L, int param)
+{
+ return (void *)luaL_checkstring(L, param);
+}
+
+static cdluaContext cdluaglctx =
+{
+ 0,
+ "GL",
+ cdContextGL,
+ cdgl_checkdata,
+ NULL,
+ 0
+};
+
+int cdluagl_open (lua_State *L)
+{
+ cdluaLuaState* cdL = cdlua_getstate(L);
+ lua_pushliteral(L, "cd");
+#if LUA_VERSION_NUM > 501
+ lua_pushglobaltable(L);
+#else
+ lua_gettable(L, LUA_GLOBALSINDEX); /* leave "cd" table at the top of the stack */
+#endif
+ cdlua_addcontext(L, cdL, &cdluaglctx);
+ return 1;
+}
+
+int luaopen_cdluagl(lua_State* L)
+{
+ return cdluagl_open(L);
+}
+
diff --git a/src/lua5/cdluagl5.def b/src/lua5/cdluagl5.def
new file mode 100644
index 0000000..80e1e2d
--- /dev/null
+++ b/src/lua5/cdluagl5.def
@@ -0,0 +1,3 @@
+EXPORTS
+ cdluagl_open
+ luaopen_cdluagl
diff --git a/src/sim/sim_primitives.c b/src/sim/sim_primitives.c
index 29fc6af..2040c66 100644
--- a/src/sim/sim_primitives.c
+++ b/src/sim/sim_primitives.c
@@ -381,7 +381,7 @@ void cdSimChord(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, d
void cdfSimSector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2)
{
- sfElipse(ctxcanvas, xc, yc, w, h, a1, a2, 0);
+ sfElipse(ctxcanvas, xc, yc, w, h, a1, a2, 1);
}
void cdfSimChord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2)