here is my modified code using arrays instead on single varibles, is this a good way to create a class for diplaying a triangle in OpenGL:
class GLTriangle
{
public:
GLTriangle();
void CreateGLTriangle( float, float, float, float, float, float, float, float, float);
void DisplayGLTriangle();
void SetColor( double, double, double );
private:
float point1[ 3 ];
float point2[ 3 ];
float point3[ 3 ];
double colorvertex[ 3 ];
};
void GLTriangle::SetColor( double r, double b, double g )
{
colorvertex[ 0 ] = r;
colorvertex[ 1 ] = b;
colorvertex[ 2 ] = g;
}
void GLTriangle::DisplayGLTriangle()
{
glBegin(GL_TRIANGLES);
glColor3f( colorvertex[ 0 ], colorvertex[ 1 ], colorvertex[ 2 ] );
glVertex3f( point1[ 0 ], point1[ 1 ], point1[ 2 ]);
glColor3f( colorvertex[ 0 ], colorvertex[ 1 ], colorvertex[ 2 ] );
glVertex3f( point2[ 0 ], point2[ 1 ], point2[ 2 ]);
glColor3f( colorvertex[ 0 ], colorvertex[ 1 ], colorvertex[ 2 ] );
glVertex3f( point3[ 0 ], point3[ 1 ], point3[ 2 ]);
glEnd();
}
void GLTriangle::CreateGLTriangle(float a, float b, float c, float d, float e, float f, float g, float h, float i)
{
point1[ 0 ] = a;
point1[ 1 ] = b;
point1[ 2 ] = c;
point2[ 0 ] = d;
point2[ 1 ] = e;
point2[ 2 ] = f;
point3[ 0 ] = g;
point3[ 1 ] = h;
point3[ 2 ] = i;
}
GLTriangle::GLTriangle()
{
point1[ 0 ] = 0.0;
point1[ 1 ] = 0.0;
point1[ 2 ] = 0.0;
point2[ 0 ] = 0.0;
point2[ 1 ] = 0.0;
point2[ 2 ] = 0.0;
point3[ 0 ] = 0.0;
point3[ 1 ] = 0.0;
point3[ 2 ] = 0.0;
}
here is where this class is used
int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
GLTriangle test;
glTranslatef(-1.5f,0.0f,-6.0f);
test.CreateGLTriangle( 0.0, 1.0, 0.0, -1.0,-1.0, 0.0, 1.0, -1.0, 0.0);
test.SetColor( 255, 0, 0 );
test.DisplayGLTriangle();
return TRUE;
}
is this good?