2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
13 #include "funcs_draw.h"
16 // direct drawing functions
19 //internal function for drawing circles and ellipses
20 void drawCircle(GLenum style
, float x
, float y
, float rx
, float ry
, float r
, float g
, float b
, float a
, float rot
, float scale_x
, float scale_y
){
21 glColor4f(r
, g
, b
, a
);
22 glDisable(GL_TEXTURE_RECTANGLE_ARB
);
24 glTranslatef(x
, y
, 0.0f
);
25 glScalef(scale_x
, scale_y
, 1.0f
);
26 glRotatef(rot
, 0.0f
, 0.0f
, -1.0f
);
29 for(double t
= 0; t
< 2*3.14159265358979; t
+= 0.05) {
30 glVertex2f(rx
* cos(t
), ry
* sin(t
));
35 glColor3f(1.0f
, 1.0f
, 1.0f
);
36 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
39 int l_draw_pixel(lua_State
*L
){
40 glColor4f(lua_tonumber(L
,3)/255.0, lua_tonumber(L
,4)/255.0, lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0);
41 glDisable(GL_TEXTURE_RECTANGLE_ARB
);
44 glVertex2f((float)lua_tonumber(L
,1), (float)lua_tonumber(L
,2));
47 glColor3f(1.0f
, 1.0f
, 1.0f
);
48 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
52 int l_draw_line(lua_State
*L
){
53 float x1
= (float)lua_tonumber(L
,1);
54 float y1
= (float)lua_tonumber(L
,2);
55 float x2
= (float)lua_tonumber(L
,3);
56 float y2
= (float)lua_tonumber(L
,4);
58 glColor4f(lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, lua_tonumber(L
,8)/255.0);
59 glDisable(GL_TEXTURE_RECTANGLE_ARB
);
66 glColor3f(1.0f
, 1.0f
, 1.0f
);
67 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
71 int l_draw_rect(lua_State
*L
){
72 float x1
= (float)lua_tonumber(L
,1);
73 float y1
= (float)lua_tonumber(L
,2);
74 float x2
= (float)lua_tonumber(L
,3);
75 float y2
= (float)lua_tonumber(L
,4);
76 float rot
= (float)lua_tonumber(L
,9);
77 float scale_x
= (float)lua_tonumber(L
,10);
78 float scale_y
= (float)lua_tonumber(L
,11);
80 glColor4f(lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, lua_tonumber(L
,8)/255.0);
81 glDisable(GL_TEXTURE_RECTANGLE_ARB
);
83 float w_half
= (x2
-x1
)/2;
84 float h_half
= (y2
-y1
)/2;
87 glTranslatef(x1
+w_half
, y1
+h_half
, 0.0f
);
89 glScalef(scale_x
, scale_y
, 1.0f
);
90 glRotatef(rot
, 0.0f
, 0.0f
, -1.0f
);
92 glBegin(GL_LINE_LOOP
);
93 glVertex2f(-w_half
, -h_half
);
94 glVertex2f(-w_half
, h_half
);
95 glVertex2f(w_half
, h_half
);
96 glVertex2f(w_half
, -h_half
);
100 glColor3f(1.0f
, 1.0f
, 1.0f
);
101 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
105 int l_draw_frect(lua_State
*L
){
106 float x1
= (float)lua_tonumber(L
,1);
107 float y1
= (float)lua_tonumber(L
,2);
108 float x2
= (float)lua_tonumber(L
,3);
109 float y2
= (float)lua_tonumber(L
,4);
110 float rot
= (float)lua_tonumber(L
,9);
111 float scale_x
= (float)lua_tonumber(L
,10);
112 float scale_y
= (float)lua_tonumber(L
,11);
114 glColor4f(lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, lua_tonumber(L
,8)/255.0);
115 glDisable(GL_TEXTURE_RECTANGLE_ARB
);
117 float w_half
= (x2
-x1
)/2;
118 float h_half
= (y2
-y1
)/2;
121 glTranslatef(x1
+w_half
, y1
+h_half
, 0.0f
);
123 glScalef(scale_x
, scale_y
, 1.0f
);
124 glRotatef(rot
, 0.0f
, 0.0f
, -1.0f
);
127 glVertex2f(-w_half
, -h_half
);
128 glVertex2f(-w_half
, h_half
);
129 glVertex2f(w_half
, h_half
);
130 glVertex2f(w_half
, -h_half
);
134 glColor3f(1.0f
, 1.0f
, 1.0f
);
135 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
139 int l_draw_circle(lua_State
*L
){
140 drawCircle(GL_LINE_LOOP
, (float)lua_tonumber(L
,1), (float)lua_tonumber(L
,2), (float)lua_tonumber(L
,3), (float)lua_tonumber(L
,3), lua_tonumber(L
,4)/255.0, lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, (float)lua_tonumber(L
,8), (float)lua_tonumber(L
,9), (float)lua_tonumber(L
,10));
144 int l_draw_fcircle(lua_State
*L
){
145 drawCircle(GL_POLYGON
, (float)lua_tonumber(L
,1), (float)lua_tonumber(L
,2), (float)lua_tonumber(L
,3), (float)lua_tonumber(L
,3), lua_tonumber(L
,4)/255.0, lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, (float)lua_tonumber(L
,8), (float)lua_tonumber(L
,9)/255.0, (float)lua_tonumber(L
,10));
149 int l_draw_ellipse(lua_State
*L
){
150 drawCircle(GL_LINE_LOOP
, (float)lua_tonumber(L
,1), (float)lua_tonumber(L
,2), (float)lua_tonumber(L
,3), (float)lua_tonumber(L
,4), lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, lua_tonumber(L
,8)/255.0, (float)lua_tonumber(L
,9),(float)lua_tonumber(L
,10), (float)lua_tonumber(L
,11));
154 int l_draw_fellipse(lua_State
*L
){
155 drawCircle(GL_POLYGON
, (float)lua_tonumber(L
,1), (float)lua_tonumber(L
,2), (float)lua_tonumber(L
,3), (float)lua_tonumber(L
,4), lua_tonumber(L
,5)/255.0, lua_tonumber(L
,6)/255.0, lua_tonumber(L
,7)/255.0, lua_tonumber(L
,8)/255.0, (float)lua_tonumber(L
,9), (float)lua_tonumber(L
,10), (float)lua_tonumber(L
,11));