Commit 46e14d4c authored by tigital's avatar tigital
Browse files

- doesn't require textures now ;-)

- added glBlend message


git-svn-id: https://pd-gem.svn.sourceforge.net/svnroot/pd-gem/trunk/Gem@130 49b2a0ca-c541-4d49-a7ef-d785e4371512
parent 897c348b
......@@ -39,11 +39,14 @@ ripple :: ripple( t_floatarg width, t_floatarg height )
inletcX = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("cX"));
inletcY = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("cY"));
inletfov = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("fov"));
//m_drawType = GL_QUADS;
m_drawType = GL_TRIANGLE_STRIP;
m_drawType = GL_POLYGON;
m_blend = 0;
alreadyInit = 0;
xsize = 0.f;
ysize = 0.f;
ctrX = 0;
ctrY = 0;
grab = -1;
precalc_ripple_amp();
}
......@@ -67,56 +70,97 @@ ripple :: ~ripple()
void ripple :: render(GemState *state)
{
int i, j;
if (m_drawType == GL_LINE_LOOP)
glLineWidth(m_linewidth);
if (m_blend) {
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE);
}
glNormal3f(0.0f, 0.0f, 1.0f);
if (state->texture && state->numTexCoords)
{
#ifdef __APPLE__
if (xsize != state->texCoords[1].s)
if (xsize != state->texCoords[1].s)
#else
if (xsize != state->texCoords[2].s)
if (xsize != state->texCoords[2].s)
#endif
alreadyInit = 0;
alreadyInit = 0;
if (!alreadyInit)
{
if (!alreadyInit)
{
#ifdef __APPLE__
xsize = state->texCoords[1].s;
ysize = state->texCoords[1].t;
xsize = state->texCoords[1].s;
ysize = state->texCoords[1].t;
#else
xsize = state->texCoords[2].s;
ysize = state->texCoords[2].t;
xsize = state->texCoords[2].s;
ysize = state->texCoords[2].t;
#endif
win_size_x = GemMan::m_width;
win_size_y = GemMan::m_height;
xyratio = win_size_x/win_size_y;
ripple_init();
precalc_ripple_vector();
alreadyInit = 1;
win_size_x = GemMan::m_width;
win_size_y = GemMan::m_height;
xyratio = win_size_x/win_size_y;
ripple_init();
precalc_ripple_vector();
alreadyInit = 1;
}
for (i = 0; i < GRID_SIZE_X - 1; i++)
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
{
glBegin(GL_POLYGON);
glTexCoord2fv(ripple_vertex[i][j].t);
glVertex2fv(ripple_vertex[i][j].x);
glTexCoord2fv(ripple_vertex[i][j + 1].t);
glVertex2fv(ripple_vertex[i][j + 1].x);
glTexCoord2fv(ripple_vertex[i + 1][j + 1].t);
glVertex2fv(ripple_vertex[i + 1][j + 1].x);
glTexCoord2fv(ripple_vertex[i + 1][j].t);
glVertex2fv(ripple_vertex[i + 1][j].x);
glEnd();
}
}
ripple_dynamics();
}
//glOrtho(-0.5, win_size_x - 0.5, -0.5, win_size_y - 0.5, CLIP_NEAR, CLIP_FAR);
//glOrtho( 0, win_size_x, 0, win_size_y, CLIP_NEAR, CLIP_FAR);
//glMatrixMode( GL_PROJECTION );
//glLoadIdentity();
//gluPerspective( fov, xyratio, 0.001, 1000000.0 );
glNormal3f(0.0f, 0.0f, 1.0f);
for (i = 0; i < GRID_SIZE_X - 1; i++)
else
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
if (!alreadyInit)
{
xsize = 1;
ysize = 1;
win_size_x = 1;
win_size_y = 1;
ripple_init();
precalc_ripple_vector();
alreadyInit = 1;
}
for (i = 0; i < GRID_SIZE_X - 1; i++)
{
glBegin(GL_POLYGON);
glTexCoord2fv(ripple_vertex[i][j].t);
glVertex2fv(ripple_vertex[i][j].x);
glTexCoord2fv(ripple_vertex[i][j + 1].t);
glVertex2fv(ripple_vertex[i][j + 1].x);
glTexCoord2fv(ripple_vertex[i + 1][j + 1].t);
glVertex2fv(ripple_vertex[i + 1][j + 1].x);
glTexCoord2fv(ripple_vertex[i + 1][j].t);
glVertex2fv(ripple_vertex[i + 1][j].x);
glEnd();
for (j = 0; j < GRID_SIZE_Y - 1; j++)
{
glBegin(m_drawType);
glTexCoord2fv(ripple_vertex[i][j].t);
glVertex2fv(ripple_vertex[i][j].t);
glTexCoord2fv(ripple_vertex[i][j + 1].t);
glVertex2fv(ripple_vertex[i][j + 1].t);
glTexCoord2fv(ripple_vertex[i + 1][j + 1].t);
glVertex2fv(ripple_vertex[i + 1][j + 1].t);
glTexCoord2fv(ripple_vertex[i + 1][j].t);
glVertex2fv(ripple_vertex[i + 1][j].t);
glEnd();
}
}
/*post("ripple_vertex[%d][%d].x[0] = %f",i,j,ripple_vertex[i][j].x[0]);
post("ripple_vertex[%d][%d].x[1] = %f",i,j,ripple_vertex[i][j].x[1]);
post("ripple_vertex[%d][%d].dt[0] = %f",i,j,ripple_vertex[i][j].dt[0]);
post("ripple_vertex[%d][%d].dt[1] = %f",i,j,ripple_vertex[i][j].dt[1]);*/
ripple_dynamics();
}
if (m_blend) {
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_BLEND);
}
ripple_dynamics();
}
/////////////////////////////////////////////////////////
//
......@@ -426,12 +470,12 @@ void ripple :: typeMess(t_symbol *type)
if (!strcmp(type->s_name, "line"))
m_drawType = GL_LINE_LOOP;
else if (!strcmp(type->s_name, "fill"))
m_drawType = GL_TRIANGLE_STRIP;
m_drawType = GL_POLYGON;
else if (!strcmp(type->s_name, "point"))
m_drawType = GL_POINTS;
else
{
error ("GEM: square draw style");
error ("GEM: no ripple draw style?");
return;
}
setModified();
......@@ -451,6 +495,8 @@ void ripple :: obj_setupCallback(t_class *classPtr)
gensym("cY"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&ripple::fovMessCallback,
gensym("fov"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&ripple::blendMessCallback,
gensym("blend"), A_FLOAT, A_NULL);
}
void ripple :: bangMessCallback(void *data)
......@@ -472,4 +518,8 @@ void ripple :: ctrYMessCallback(void *data, t_floatarg center)
void ripple :: fovMessCallback(void *data, t_floatarg size)
{
GetMyClass(data)->fov=((float)size);
}
\ No newline at end of file
}
void ripple :: blendMessCallback(void *data, t_floatarg size)
{
GetMyClass(data)->m_blend=((int)size);
}
......@@ -120,6 +120,7 @@ class GEM_EXTERN ripple : public GemShape
int win_size_x;
int win_size_y;
int xyratio;
int m_blend;
float xsize, ysize;
float fov;
RIPPLE_VECTOR ripple_vector[GRID_SIZE_X][GRID_SIZE_Y];
......@@ -143,6 +144,7 @@ class GEM_EXTERN ripple : public GemShape
static void ctrXMessCallback(void *data, t_floatarg center);
static void ctrYMessCallback(void *data, t_floatarg center);
static void fovMessCallback(void *data, t_floatarg size);
static void blendMessCallback(void *data, t_floatarg size);
};
#endif // for header file
......@@ -72,6 +72,7 @@ rubber :: rubber( t_floatarg width, t_floatarg height )
//m_drawType = GL_LINE_LOOP;
m_drawType = GL_POLYGON;
alreadyInit = 0;
m_blend = 0;
}
/////////////////////////////////////////////////////////
......@@ -190,62 +191,100 @@ void rubber :: rubber_init()
void rubber :: render(GemState *state)
{
int k, i, j;
if (m_drawType == GL_LINE_LOOP)
glLineWidth(m_linewidth);
glOrtho(-0.5, win_size_x - 0.5, -0.5, win_size_y - 0.5, CLIP_NEAR, CLIP_FAR);
//glOrtho(0.5, GemMan::m_width - 0.5, 0.5, GemMan::m_height - 0.5, CLIP_NEAR, CLIP_FAR);
if (m_blend) {
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE);
}
glNormal3f(0.0f, 0.0f, 1.0f);
if (state->texture && state->numTexCoords)
{
#ifdef __APPLE__
if (xsize != state->texCoords[1].s)
if (xsize != state->texCoords[1].s)
#else
if (xsize != state->texCoords[2].s)
if (xsize != state->texCoords[2].s)
#endif
alreadyInit = 0;
alreadyInit = 0;
if (!alreadyInit)
{
if (!alreadyInit)
{
#ifdef __APPLE__
xsize = state->texCoords[1].s;
ysize = state->texCoords[1].t;
xsize = state->texCoords[1].s;
ysize = state->texCoords[1].t;
#else
xsize = state->texCoords[2].s;
ysize = state->texCoords[2].t;
xsize = state->texCoords[2].s;
ysize = state->texCoords[2].t;
#endif
rubber_init();
alreadyInit = 1;
}
if (m_drawType == GL_LINE_LOOP)
glLineWidth(1/*m_linewidth*/);
glOrtho(-0.5, win_size_x - 0.5, -0.5, win_size_y - 0.5, CLIP_NEAR, CLIP_FAR);
//glOrtho(0.5, GemMan::m_width - 0.5, 0.5, GemMan::m_height - 0.5, CLIP_NEAR, CLIP_FAR);
rubber_init();
alreadyInit = 1;
}
#define _WIREFRAME
#ifdef WIREFRAME
for (k = 0; k < spring_count; k++)
{
glBegin(GL_LINES);
glVertex3fv(mass[spring[k].i].x);
glVertex3fv(mass[spring[k].j].x);
glEnd();
k = 0;
for (i = 0; i < GRID_SIZE_X - 1; i++)
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
{
glBegin(GL_POLYGON);
glTexCoord2fv(mass[k].t);
glVertex3fv(mass[k].x);
glTexCoord2fv(mass[k + 1].t);
glVertex3fv(mass[k + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y + 1].t);
glVertex3fv(mass[k + GRID_SIZE_Y + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y].t);
glVertex3fv(mass[k + GRID_SIZE_Y].x);
glEnd();
k++;
}
k++;
}
rubber_dynamics();
}
#else
k = 0;
for (i = 0; i < GRID_SIZE_X - 1; i++)
else
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
if (!alreadyInit)
{
glBegin(GL_POLYGON);
glTexCoord2fv(mass[k].t);
glVertex3fv(mass[k].x);
glTexCoord2fv(mass[k + 1].t);
glVertex3fv(mass[k + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y + 1].t);
glVertex3fv(mass[k + GRID_SIZE_Y + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y].t);
glVertex3fv(mass[k + GRID_SIZE_Y].x);
glEnd();
rubber_init();
alreadyInit = 1;
}
k = 0;
for (i = 0; i < GRID_SIZE_X - 1; i++)
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
{
glBegin(m_drawType);
glTexCoord2fv(mass[k].t);
glVertex3fv(mass[k].x);
glTexCoord2fv(mass[k + 1].t);
glVertex3fv(mass[k + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y + 1].t);
glVertex3fv(mass[k + GRID_SIZE_Y + 1].x);
glTexCoord2fv(mass[k + GRID_SIZE_Y].t);
glVertex3fv(mass[k + GRID_SIZE_Y].x);
glEnd();
k++;
}
k++;
}
k++;
rubber_dynamics();
/*for (k = 0; k < spring_count; k++)
{
glBegin(GL_LINES);
glVertex3fv(mass[spring[k].i].x);
glVertex3fv(mass[spring[k].j].x);
glEnd();
}*/
}
#endif
rubber_dynamics();
}
/*
......@@ -406,8 +445,8 @@ void rubber :: obj_setupCallback(t_class *classPtr)
gensym("cX"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&rubber::ctrYMessCallback,
gensym("cY"), A_FLOAT, A_NULL);
//class_addmethod(classPtr, (t_method)&rubber::otherMessCallback,
// gensym("Ot"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&rubber::blendMessCallback,
gensym("blend"), A_FLOAT, A_NULL);
}
void rubber :: bangMessCallback(void *data)
{
......@@ -425,7 +464,7 @@ void rubber :: ctrYMessCallback(void *data, t_floatarg center)
{
GetMyClass(data)->ctrYMess((float)center);
}
//void rubber :: otherMessCallback(void *data, t_floatarg other)
//{
// GetMyClass(data)->otherMess((float)other);
//}
\ No newline at end of file
void rubber :: blendMessCallback(void *data, t_floatarg size)
{
GetMyClass(data)->m_blend=((int)size);
}
\ No newline at end of file
......@@ -86,6 +86,7 @@ class GEM_EXTERN rubber : public GemShape
int m_size;
int m_speed;
int m_blend;
int alreadyInit;
float xsize, ysize;
int win_size_x, win_size_y;
......@@ -98,7 +99,7 @@ class GEM_EXTERN rubber : public GemShape
static void heightMessCallback(void *data, t_floatarg height);
static void ctrXMessCallback(void *data, t_floatarg center);
static void ctrYMessCallback(void *data, t_floatarg center);
//static void otherMessCallback(void *data, t_floatarg other);
static void blendMessCallback(void *data, t_floatarg size);
};
#endif // for header file
......@@ -56,6 +56,7 @@ slideSquares :: slideSquares(t_floatarg width, t_floatarg height)
// the height inlet
m_inletH = inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("Ht"));
m_drawType = GL_QUADS;
m_blend = 0;
slide_init();
}
......@@ -75,24 +76,25 @@ slideSquares :: ~slideSquares()
void slideSquares :: render(GemState *state)
{
int i;
/*if (!init){
xsize = state->texCoords[1].s;
ysize = state->texCoords[1].t;
Init( );
init = 1;
}*/
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
//glTranslatef( 0.0f, 0.0f, 0.1f );
//glColor4f( 0.5f, 0.5f, 0.5f, 0.75f );
//glNormal3f(0.0f, 0.0f, 1.0f);
glColor4f( 0.5f, 0.5f, 0.5f, 0.75f );
glNormal3f(0.0f, 0.0f, 1.0f);
//glScalef( 1.f, 0.8f, 1.f );
if (m_drawType == GL_LINE_LOOP)
glLineWidth(m_linewidth);
if (state->texture )//&& state->numTexCoords)
if (m_blend) {
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE);
}
int curCoord = 0;
if (state->texture && state->numTexCoords)
{
int curCoord = 0;
glBegin(m_drawType);
for (i=0; i<= 31; i++){
glTexCoord2f(Sliders[i].U, Sliders[i].V );
......@@ -113,42 +115,34 @@ void slideSquares :: render(GemState *state)
Slide( i );
}
glEnd();
/*glBegin(m_drawType);
}
else
{
glBegin(m_drawType);
for (i=0; i<= 31; i++){
glTexCoord2f(Sliders[i].U*state->texCoords[0].s, Sliders[i].V*state->texCoords[0].t );
glTexCoord2f(Sliders[i].U, Sliders[i].V );
glVertex3f(m_size*(Sliders[i].X - 0.1), m_height*(Sliders[i].Y - 0.1), 0.0);
if (state->numTexCoords > 1) curCoord = 1;
glTexCoord2f((Sliders[i].U+0.1)*state->texCoords[1].s, Sliders[i].V*state->texCoords[1].t );
glTexCoord2f( Sliders[i].U+0.1, Sliders[i].V );
glVertex3f(m_size*(Sliders[i].X + 0.1), m_height*(Sliders[i].Y - 0.1), 0.0);
if (state->numTexCoords > 2) curCoord = 2;
glTexCoord2f((Sliders[i].U+0.1)*state->texCoords[2].s, (Sliders[i].V+0.1)*state->texCoords[2].t);
glTexCoord2f( Sliders[i].U+0.1, Sliders[i].V+0.1 );
glVertex3f(m_size*(Sliders[i].X + 0.1), m_height*(Sliders[i].Y + 0.1), 0.0);
if (state->numTexCoords > 3) curCoord = 3;
glTexCoord2f(Sliders[i].U*state->texCoords[3].s, (Sliders[i].V+0.1)*state->texCoords[3].t);
glTexCoord2f(Sliders[i].U, Sliders[i].V+0.1);
glVertex3f(m_size*(Sliders[i].X - 0.1), m_height*(Sliders[i].Y + 0.1), 0.0);
Slide( i );
}
glEnd();*/
glEnd();
}
else
{
glBegin(m_drawType);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-m_size, -m_height, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( m_size, -m_height, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( m_size, m_height, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-m_size, m_height, 0.0f);
glEnd();
if (m_blend) {
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_BLEND);
}
if (m_drawType == GL_LINE_LOOP)
glLineWidth(1.0);
}
void slideSquares :: slide_init()
{
......@@ -160,11 +154,11 @@ void slideSquares :: slide_init()
//Sliders[i].V = (Sliders[i].Y + 0.45);
Sliders[i].Speed = ourRand(1)/320 + 1/1600;
post("sliders[%d].U = %f",i,Sliders[i].U);
/*post("sliders[%d].U = %f",i,Sliders[i].U);
post("sliders[%d].X = %f",i,Sliders[i].X);
post("sliders[%d].Y = %f",i,Sliders[i].Y);
post("sliders[%d].V = %f",i,Sliders[i].V);
post("sliders[%d].speed = %f",i,Sliders[i].Speed);
post("sliders[%d].speed = %f",i,Sliders[i].Speed);*/
}
}
GLvoid slideSquares :: Slide( int i )
......@@ -179,11 +173,13 @@ GLvoid slideSquares :: Slide( int i )
Sliders[i].Speed = ourRand(1)/320 + 1/1600;
} else
Sliders[i].X = Sliders[i].U*2 -1;
//printf("Sliders[0].U = %f\n",Sliders[0].U);
//printf("Sliders[0].X = %f\n",Sliders[0].X);
//printf("Sliders[0].Y = %f\n",Sliders[0].Y);
//printf("Sliders[0].V = %f\n",Sliders[0].V);
//printf("Sliders[0].Speed = %f\n",Sliders[0].Speed);
/*
printf("Sliders[0].U = %f\n",Sliders[0].U);
printf("Sliders[0].X = %f\n",Sliders[0].X);
printf("Sliders[0].Y = %f\n",Sliders[0].Y);
printf("Sliders[0].V = %f\n",Sliders[0].V);
printf("Sliders[0].Speed = %f\n",Sliders[0].Speed);
*/
}
/////////////////////////////////////////////////////////
......@@ -210,7 +206,7 @@ void slideSquares :: typeMess(t_symbol *type)
m_drawType = GL_POINTS;
else
{
error ("GEM: square draw style");
error ("GEM: slideSquares draw style");
return;
}
setModified();
......@@ -224,9 +220,15 @@ void slideSquares :: obj_setupCallback(t_class *classPtr)
{
class_addmethod(classPtr, (t_method)&slideSquares::heightMessCallback,
gensym("Ht"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&slideSquares::blendMessCallback,
gensym("blend"), A_FLOAT, A_NULL);
}
void slideSquares :: heightMessCallback(void *data, t_floatarg size)
{
GetMyClass(data)->heightMess((float)size);
}
void slideSquares :: blendMessCallback(void *data, t_floatarg size)
{
GetMyClass(data)->m_blend=((int)size);
}
\ No newline at end of file
......@@ -70,12 +70,14 @@ class GEM_EXTERN slideSquares : public GemShape
GLvoid Slide( int i );
void slide_init();
float xsize, ysize;
int m_blend;
private:
//////////
// Static member functions
static void heightMessCallback(void *data, t_floatarg size);
static void blendMessCallback(void *data, t_floatarg size);
};
#endif // for header file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment