Commit aff3787b authored by Maciej Suminski's avatar Maciej Suminski

Fixed drawing circles and semicircles using display lists.

parent af5a695c
...@@ -66,7 +66,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -66,7 +66,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
// Initialize the flags // Initialize the flags
isCreated = false;
isDeleteSavedPixels = true; isDeleteSavedPixels = true;
isGlewInitialized = false; isGlewInitialized = false;
isFrameBufferInitialized = false; isFrameBufferInitialized = false;
...@@ -114,14 +113,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -114,14 +113,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
InitTesselatorCallbacks( tesselator ); InitTesselatorCallbacks( tesselator );
gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE ); gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
// Buffered semicircle & circle vertices // Compute unit semicircle & circle vertices and store them in a buffer for faster drawing
// (3 vertices per triangle) * (number of points to draw a circle) computeCircleVbo();
precomputedContainer = new VBO_CONTAINER( 3 * CIRCLE_POINTS );
// Compute the unit circles, used for speed up of the circle drawing
verticesCircle = new VBO_ITEM( precomputedContainer );
computeUnitCircle();
verticesCircle->Finish();
} }
...@@ -129,6 +122,11 @@ OPENGL_GAL::~OPENGL_GAL() ...@@ -129,6 +122,11 @@ OPENGL_GAL::~OPENGL_GAL()
{ {
glFlush(); glFlush();
if( glIsList( displayListSemiCircle ) )
glDeleteLists( displayListSemiCircle, 1 );
if( glIsList( displayListCircle ) )
glDeleteLists( displayListCircle, 1 );
delete verticesCircle; delete verticesCircle;
delete precomputedContainer; delete precomputedContainer;
...@@ -331,6 +329,7 @@ void OPENGL_GAL::initGlew() ...@@ -331,6 +329,7 @@ void OPENGL_GAL::initGlew()
} }
initVertexBufferObjects(); initVertexBufferObjects();
computeCircleDisplayLists();
isGlewInitialized = true; isGlewInitialized = true;
} }
...@@ -1502,12 +1501,11 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth ) ...@@ -1502,12 +1501,11 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth )
} }
void OPENGL_GAL::computeUnitCircle() void OPENGL_GAL::computeCircleVbo()
{ {
displayListCircle = glGenLists( 1 ); // (3 vertices per triangle) * (number of points to draw a circle)
glNewList( displayListCircle, GL_COMPILE ); precomputedContainer = new VBO_CONTAINER( 3 * CIRCLE_POINTS );
verticesCircle = new VBO_ITEM( precomputedContainer );
glBegin( GL_TRIANGLES );
// Compute the circle points for a given number of segments // Compute the circle points for a given number of segments
// Insert in a display list and a vector // Insert in a display list and a vector
...@@ -1526,29 +1524,38 @@ void OPENGL_GAL::computeUnitCircle() ...@@ -1526,29 +1524,38 @@ void OPENGL_GAL::computeUnitCircle()
0.0f // z 0.0f // z
}; };
glVertex2d( 0, 0 );
verticesCircle->PushVertex( &v0 ); verticesCircle->PushVertex( &v0 );
glVertex2d( v1.x, v1.y );
verticesCircle->PushVertex( &v1 ); verticesCircle->PushVertex( &v1 );
glVertex2d( v2.x, v2.y );
verticesCircle->PushVertex( &v2 ); verticesCircle->PushVertex( &v2 );
} }
glEnd(); verticesCircle->Finish();
glEndList();
} }
void OPENGL_GAL::computeUnitSemiCircle() void OPENGL_GAL::computeCircleDisplayLists()
{ {
// Circle display list
displayListCircle = glGenLists( 1 );
glNewList( displayListCircle, GL_COMPILE );
glBegin( GL_TRIANGLES );
for( int i = 0; i < CIRCLE_POINTS; ++i )
{
glVertex2d( 0.0, 0.0 );
glVertex2d( cos( 2.0 * M_PI / CIRCLE_POINTS * i ),
sin( 2.0 * M_PI / CIRCLE_POINTS * i ) );
glVertex2d( cos( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ),
sin( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ) );
}
glEnd();
glEndList();
// Semicircle display list
displayListSemiCircle = glGenLists( 1 ); displayListSemiCircle = glGenLists( 1 );
glNewList( displayListSemiCircle, GL_COMPILE ); glNewList( displayListSemiCircle, GL_COMPILE );
glBegin( GL_TRIANGLES ); glBegin( GL_TRIANGLES );
for( int i = 0; i < CIRCLE_POINTS / 2; ++i ) for( int i = 0; i < CIRCLE_POINTS / 2; ++i )
{ {
glVertex2d( 0.0, 0.0 ); glVertex2d( 0.0, 0.0 );
...@@ -1557,9 +1564,7 @@ void OPENGL_GAL::computeUnitSemiCircle() ...@@ -1557,9 +1564,7 @@ void OPENGL_GAL::computeUnitSemiCircle()
glVertex2d( cos( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ), glVertex2d( cos( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ),
sin( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ) ); sin( 2.0 * M_PI / CIRCLE_POINTS * ( i + 1 ) ) );
} }
glEnd(); glEnd();
glEndList(); glEndList();
} }
......
...@@ -337,10 +337,10 @@ private: ...@@ -337,10 +337,10 @@ private:
wxEvtHandler* mouseListener; wxEvtHandler* mouseListener;
wxEvtHandler* paintListener; wxEvtHandler* paintListener;
// Display lists (used in shaderless mode) // VBO buffers & display lists (used in immediate mode)
VBO_CONTAINER* precomputedContainer; ///< Container for storing display lists VBO_CONTAINER* precomputedContainer; ///< Container for storing display lists
VBO_ITEM* verticesCircle; ///< Buffer for circle & semicircle vertices
GLuint displayListCircle; ///< Circle display list GLuint displayListCircle; ///< Circle display list
VBO_ITEM* verticesCircle;
GLuint displayListSemiCircle; ///< Semi circle display list GLuint displayListSemiCircle; ///< Semi circle display list
// Vertex buffer objects related fields // Vertex buffer objects related fields
...@@ -372,8 +372,8 @@ private: ...@@ -372,8 +372,8 @@ private:
SHADER_STROKED_CIRCLE, SHADER_STROKED_CIRCLE,
} SHADER_TYPE; } SHADER_TYPE;
SHADER shader; ///< There is only one shader used for different objects SHADER shader; ///< There is only one shader used for different objects
int shaderAttrib; ///< Location of shader attributes (for glVertexAttribPointer) int shaderAttrib; ///< Location of shader attributes (for glVertexAttribPointer)
// Cursor // Cursor
int cursorSize; ///< Size of the cursor in pixels int cursorSize; ///< Size of the cursor in pixels
...@@ -391,7 +391,6 @@ private: ...@@ -391,7 +391,6 @@ private:
GLuint textureBackup; ///< Backup texture handle GLuint textureBackup; ///< Backup texture handle
// Internal flags // Internal flags
bool isCreated;
bool isGlewInitialized; ///< Is GLEW initialized? bool isGlewInitialized; ///< Is GLEW initialized?
bool isFrameBufferInitialized; ///< Are the frame buffers initialized? bool isFrameBufferInitialized; ///< Are the frame buffers initialized?
bool isVboInitialized; bool isVboInitialized;
...@@ -412,14 +411,12 @@ private: ...@@ -412,14 +411,12 @@ private:
void drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle ); void drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle );
void drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle ); void drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle );
/// Compute the points of a unit circle. /// Compute the points of an unit circle & semicircle and store them in VBO.
void computeUnitCircle(); void computeCircleVbo();
/// Compute the points of a unit semi circle. /// Compute the points of an unit circle & semicircle and store them in display lists
void computeUnitSemiCircle(); /// for drawing in immediate mode.
void computeCircleDisplayLists();
/// Compute the points of a unit arc.
// void computeUnitArcs(); // TODO not used
// Event handling // Event handling
/** /**
......
Markdown is supported
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