GLWidget
::GLWidget(QWidget *parent
) :{
connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL()));
timer.start(1000);
}
void GLWidget::initializeGL(int w, int h) {
glClearColor(0.2f, 0.2f, 0.2f, 1);
glViewport(0, 0, w, h);
// Setup light
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = {2.0f, 5.0f, 5.0f, 0.0f };
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_DOUBLE);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthFunc(GL_LESS);
glEnable(GL_COLOR_MATERIAL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 0.0001, 1000.0);
glMatrixMode(GL_MODELVIEW);
current_view= TOP_VIEW;
}
/ Display
void GLWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
setView();
if (current_view == EXPLORING_VIEW)
calculate_lookpoint();
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz);
// Draw axis and add points
drawAxis();
int ind;
Skyline s;
if (s.skylineGenerated()) {
drawCube();
cout << "Generated" << endl;
}
swapBuffers();
}
void GLWidget::drawCube(void){
cout << "Drawn\n";
glTranslatef(0.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glutSolidCube(2.0);
update();
}
// Reshape
void GLWidget::resizeGL(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (48.0, (GLfloat) w/(GLfloat) h, 10.0, 800.0);
glMatrixMode (GL_MODELVIEW);
}
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL()));
timer.start(1000);
}
void GLWidget::initializeGL(int w, int h) {
glClearColor(0.2f, 0.2f, 0.2f, 1);
glViewport(0, 0, w, h);
// Setup light
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = {2.0f, 5.0f, 5.0f, 0.0f };
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_DOUBLE);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthFunc(GL_LESS);
glEnable(GL_COLOR_MATERIAL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 0.0001, 1000.0);
glMatrixMode(GL_MODELVIEW);
current_view= TOP_VIEW;
}
/ Display
void GLWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
setView();
if (current_view == EXPLORING_VIEW)
calculate_lookpoint();
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz);
// Draw axis and add points
drawAxis();
int ind;
Skyline s;
if (s.skylineGenerated()) {
drawCube();
cout << "Generated" << endl;
}
swapBuffers();
}
void GLWidget::drawCube(void){
cout << "Drawn\n";
glTranslatef(0.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glutSolidCube(2.0);
update();
}
// Reshape
void GLWidget::resizeGL(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (48.0, (GLfloat) w/(GLfloat) h, 10.0, 800.0);
glMatrixMode (GL_MODELVIEW);
}
To copy to clipboard, switch view to plain text mode
Bookmarks