GLC_lib Logo
      GLC_lib
OpenGL Library Class Support This Project

Home

Help
Examples
Screenshots
Download
Link
Forum
News

Example01 : Circle display

 

 

Example01_img

 

This example show how using GLC_lib to display a circle with the class GLC_Circle.

Source of the example01:

Download Source and binaries of this example.

GLWidget class

GLWidget class inherits QGLWidget. This class is a Widget for rendering OpenGL graphics. (See QT4 reference)

 

This is the class in which we include code to display the circle.

glwidget.h

#ifndef GLWIDGET_H_
#define GLWIDGET_H_

#include <QGLWidget>

//////////////////////////// GLC specific///////////////////////////////////////
// The factory

#include <GLC_Factory>
// The Viewport with a default camera
#include <GLC_Viewport>
//////////////////////////End GLC specific/////////////////////////////////////

class GLWidget : public QGLWidget

{
public:
	GLWidget(QWidget *p_parent);
	~GLWidget();	

private:

	void initializeGL();
	void paintGL();
	void resizeGL(int width, int height);

		
private:
//////////////////////////// GLC specific///////////////////////////////////////
  GLC_Factory* m_pFactory;
  GLC_3DViewInstance m_Circle;
  GLC_Viewport m_GlView;	
//////////////////////////End GLC specific/////////////////////////////////////
};

#endif /*GLWIDGET_H_*/

Include :

The first header to include is GLC_Factory to built all GLC_lib geometry, material and texture.

The second header is GLC_Viewport to manage GLC_lib viewport.

Private members :

After we have to declare these variables :

glwidget.cpp

#include <QtDebug>
#include "glwidget.h"


GLWidget::GLWidget(QWidget *p_parent)
: QGLWidget(p_parent)
, m_pFactory(GLC_Factory::instance(this->context()))   // Get Factory instance

, m_Circle(m_pFactory->createCircle(0.2))  // Circle radius
, m_GlView(this)
{

	/* By default :
	Camera Eye (0, 0, 1)
	Camera Target (0, 0, 0)
	Camera Vectup (0, 1, 0)
	*/
}

GLWidget::~GLWidget()
{
	delete m_pFactory;
}

void GLWidget::initializeGL()
{
//////////////////////////// GLC specific///////////////////////////////////////
	m_GlView.initGl();
//////////////////////////End GLC specific/////////////////////////////////////
}

void GLWidget::paintGL()
{
	// Clear screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Load identity matrix
	glLoadIdentity();

//////////////////////////// GLC specific///////////////////////////////////////
	// define view matrix
	m_GlView.glExecuteCam();

	// Display the circle

	m_Circle.glExecute();
//////////////////////////End GLC specific/////////////////////////////////////

}

void GLWidget::resizeGL(int width, int height)
{

//////////////////////////// GLC specific///////////////////////////////////////
	m_GlView.setWinGLSize(width, height);	// Compute window aspect ratio
//////////////////////////End GLC specific/////////////////////////////////////
}

Constructor :

Destructor :

initializedGL :

paintGL method :

resizeGL :

In this example we take the default camera position. Have a look to GLC_Camera constructor.

 

MainWindow Class.

QT4 main application window.

Nothing specific to add for GLC_lib

mainwindow.h

#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_

#include <QMainWindow>

class GLWidget;

class MainWindow : public QMainWindow
{
	Q_OBJECT
	
public:
	MainWindow();
			
//private members
private:
	GLWidget *p_GLWidget;

};

#endif /*MAINWINDOW_H_*/

mainwindow.cpp

#include <QtGui>
#include "mainwindow.h"
#include "glwidget.h"

MainWindow::MainWindow()
: p_GLWidget(NULL)
{	
	p_GLWidget= new GLWidget(this);

	setCentralWidget(p_GLWidget);	
}

Application

#include <QApplication>
#include "mainwindow.h"

int main(int argc, char **argv)
{	
	QApplication app(argc, argv);	
	MainWindow mainWin;

	mainWin.resize(600, 400);
	mainWin.show();	
	return app.exec();
}

 

SourceForge.net Logo

©2005-2011 Laurent Ribon