I am not getting any Errors but the function that i am using as a SLOT doesn't get hit when I click on the button.
#include "Example.h"
#include "GLWidget.h"
{
ui.setupUi(this);
connect(ui.button,SIGNAL(clicked()),ui.Gl_Helper,SLOT(vDrawPoly()));
}
Example::~Example()
{
}
And the GLWidget code:
/*
* GLWidget.cpp
*
* Created on: Sep 22, 2011
*
*/
#include <QtOpenGL>
#include "GLWidget.h"
GLWidget
::GLWidget(QWidget *parent
){
pos = 0.0f;
}
GLWidget::~GLWidget()
{
makeCurrent();
glDeleteLists(1, 1);
}
void GLWidget::initializeGL()
{
glClearColor(1.0f,0.0f,0.0f,0.0f);
// object = makeObject();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Create light components
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 1.0f, 1.0f, 1.0, 1.0f };
GLfloat specularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat position[] = { -100.0f, 100.0f, 0.0f, 1.0f };
// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0f,0.0f, 0.0f);
//glScaled(scale,scale,scale);
glRotated(0.0f, 1.0f, 0.0f, 0.0f);
glRotated(0.0f, 0.0f, 1.0f, 0.0f);
glRotated(0.0f, 0.0f, 0.0f, 1.0f);
glCallList(1);
glPushMatrix();
glTranslated(sPs.fX,sPs.fY, sPs.fZ);
glRotatef(sR.fAngle,sR.fX_R,sR.fY_R,sR.fZ_R);
glColor3f(sClr.fR, sClr.fG, sClr.fB);
glLineWidth(5.0f);
glBegin(GL_POLYGON);
glVertex2d(-pos, pos);
glVertex2d(-pos, -pos);
glVertex2d(pos, -pos);
glVertex2d(pos, pos);
glEnd();
glPopMatrix();
//vDrawPoly();
}
void GLWidget::resizeGL(int width, int height)
{
glViewport(0.0f, 0.0f, 800, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
glOrtho(-200, 300, -300, 300, -300, 300.0);
glMatrixMode(GL_MODELVIEW);
}
{
// lastPos = event->pos();
}
{
}
void GLWidget::vDrawPoly()
{
sPs.vInit(0.0f,0.0f,0.0f);
sR.vInit(0.0f,0.0f,0.0f,0.0f);
sClr.vInit(1.0f, 1.0f, 1.0f);
pos = 50;
updateGL();
/*glPushMatrix();
glTranslated(10.0f,10.0f, 1.0f);
glRotatef(0.0f,0.0f,0.0f,0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(5.0f);
glBegin(GL_POLYGON);
glVertex2d(-50.0f, 50.0f);
glVertex2d(-50.0f, -50.0f);
glVertex2d(50.0f, -50.0f);
glVertex2d(50.0f, 50.0f);
glEnd();
glPopMatrix();*/
}
#include "Example.h"
#include "GLWidget.h"
Example::Example(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.button,SIGNAL(clicked()),ui.Gl_Helper,SLOT(vDrawPoly()));
}
Example::~Example()
{
}
And the GLWidget code:
/*
* GLWidget.cpp
*
* Created on: Sep 22, 2011
*
*/
#include <QtOpenGL>
#include "GLWidget.h"
GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent)
{
pos = 0.0f;
}
GLWidget::~GLWidget()
{
makeCurrent();
glDeleteLists(1, 1);
}
void GLWidget::initializeGL()
{
glClearColor(1.0f,0.0f,0.0f,0.0f);
// object = makeObject();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Create light components
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 1.0f, 1.0f, 1.0, 1.0f };
GLfloat specularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat position[] = { -100.0f, 100.0f, 0.0f, 1.0f };
// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0f,0.0f, 0.0f);
//glScaled(scale,scale,scale);
glRotated(0.0f, 1.0f, 0.0f, 0.0f);
glRotated(0.0f, 0.0f, 1.0f, 0.0f);
glRotated(0.0f, 0.0f, 0.0f, 1.0f);
glCallList(1);
glPushMatrix();
glTranslated(sPs.fX,sPs.fY, sPs.fZ);
glRotatef(sR.fAngle,sR.fX_R,sR.fY_R,sR.fZ_R);
glColor3f(sClr.fR, sClr.fG, sClr.fB);
glLineWidth(5.0f);
glBegin(GL_POLYGON);
glVertex2d(-pos, pos);
glVertex2d(-pos, -pos);
glVertex2d(pos, -pos);
glVertex2d(pos, pos);
glEnd();
glPopMatrix();
//vDrawPoly();
}
void GLWidget::resizeGL(int width, int height)
{
glViewport(0.0f, 0.0f, 800, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
glOrtho(-200, 300, -300, 300, -300, 300.0);
glMatrixMode(GL_MODELVIEW);
}
void GLWidget::mousePressEvent(QMouseEvent *event)
{
// lastPos = event->pos();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
}
void GLWidget::vDrawPoly()
{
sPs.vInit(0.0f,0.0f,0.0f);
sR.vInit(0.0f,0.0f,0.0f,0.0f);
sClr.vInit(1.0f, 1.0f, 1.0f);
pos = 50;
updateGL();
/*glPushMatrix();
glTranslated(10.0f,10.0f, 1.0f);
glRotatef(0.0f,0.0f,0.0f,0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(5.0f);
glBegin(GL_POLYGON);
glVertex2d(-50.0f, 50.0f);
glVertex2d(-50.0f, -50.0f);
glVertex2d(50.0f, -50.0f);
glVertex2d(50.0f, 50.0f);
glEnd();
glPopMatrix();*/
}
To copy to clipboard, switch view to plain text mode
The function that i have written for SLOT is vDrawPoly(), doesn't get called. I have posted only code in .cpp files as .h isnot requred and i also have .ui file which is generated.
Bookmarks