fixed Qt opengl bugs
This commit is contained in:
parent
cfbec41c44
commit
ee7f0e3d69
@ -11,8 +11,8 @@ out vec4 outColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 halfScreen = screenSize/2;
|
vec2 halfScreen = screenSize/2;
|
||||||
vec2 screenPos = gl_FragCoord.xy/gl_FragCoord.w + camera.xy;
|
vec2 screenPos = gl_FragCoord.xy + camera.xy;
|
||||||
vec2 texCoord = (screenPos-halfScreen)/200;
|
vec2 texCoord = (screenPos-halfScreen)/200;
|
||||||
vec3 texColor = texture(colorMap, texCoord).xyz;
|
vec3 texColor = texelFetch(colorMap, ivec2(screenPos*camera.z)).xyz;
|
||||||
outColor = vec4(texColor, 1.0);
|
outColor = vec4(texColor, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ DrawWidget::DrawWidget(QWidget *parent) :
|
|||||||
QOpenGLWidget(parent),
|
QOpenGLWidget(parent),
|
||||||
m_Qt_fbo(NULL)
|
m_Qt_fbo(NULL)
|
||||||
{
|
{
|
||||||
connect(&openglRefreshTimer, SIGNAL(timeout()), this, SLOT(repaint()));
|
new_simulation = false;
|
||||||
openglRefreshTimer.start(16);
|
update_needed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawWidget::~DrawWidget()
|
DrawWidget::~DrawWidget()
|
||||||
@ -35,9 +35,24 @@ void DrawWidget::initializeGL()
|
|||||||
|
|
||||||
void DrawWidget::paintGL()
|
void DrawWidget::paintGL()
|
||||||
{
|
{
|
||||||
|
if(new_simulation)
|
||||||
|
{
|
||||||
|
m_pipeline = new PixelPipeline(m_map);
|
||||||
|
m_pipeline->setTargetFBO(m_Qt_fbo);
|
||||||
|
m_pipeline->resizeGL(m_width, m_height);
|
||||||
|
renderer.setScene(m_map);
|
||||||
|
new_simulation = false;
|
||||||
|
}
|
||||||
|
else if(update_needed)
|
||||||
|
m_pipeline->updateChanges();
|
||||||
renderer.renderGL();
|
renderer.renderGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawWidget::updateDudesBehavior()
|
||||||
|
{
|
||||||
|
update_needed = true;
|
||||||
|
}
|
||||||
|
|
||||||
void DrawWidget::resizeGL(int w, int h)
|
void DrawWidget::resizeGL(int w, int h)
|
||||||
{
|
{
|
||||||
m_width = w;
|
m_width = w;
|
||||||
@ -58,12 +73,10 @@ void DrawWidget::startSimulation(GenerateFunction genFunc, std::vector<BehaviorF
|
|||||||
delete m_pipeline;
|
delete m_pipeline;
|
||||||
m_map = NULL;
|
m_map = NULL;
|
||||||
}
|
}
|
||||||
m_map = new MapScene(behaveFuncs.size(), 200, 100);
|
m_map = new MapScene(behaveFuncs.size(), 300);
|
||||||
genFunc((Map*)m_map);
|
genFunc((Map*)m_map);
|
||||||
m_pipeline = new PixelPipeline(m_map);
|
new_simulation = true;
|
||||||
m_pipeline->setTargetFBO(m_Qt_fbo);
|
repaint();
|
||||||
m_pipeline->resizeGL(m_width, m_height);
|
|
||||||
renderer.setScene(m_map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// INPUT EVENTS
|
// INPUT EVENTS
|
||||||
@ -71,7 +84,10 @@ void DrawWidget::startSimulation(GenerateFunction genFunc, std::vector<BehaviorF
|
|||||||
void DrawWidget::mouseMoveEvent(QMouseEvent *event)
|
void DrawWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(grabbedMouse)
|
if(grabbedMouse)
|
||||||
|
{
|
||||||
m_pipeline->cameraMove(event->globalX() - lastMousePos.x(), event->globalY() - lastMousePos.y());
|
m_pipeline->cameraMove(event->globalX() - lastMousePos.x(), event->globalY() - lastMousePos.y());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
lastMousePos = event->globalPos();
|
lastMousePos = event->globalPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,4 +124,5 @@ void DrawWidget::mouseReleaseEvent(QMouseEvent* event)
|
|||||||
void DrawWidget::wheelEvent(QWheelEvent *event)
|
void DrawWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
m_pipeline->cameraZoom(event->delta());
|
m_pipeline->cameraZoom(event->delta());
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <sparrowrenderer.h>
|
#include <sparrowrenderer.h>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "team.h"
|
#include "team.h"
|
||||||
@ -18,7 +17,6 @@ class DrawWidget : public QOpenGLWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
SparrowRenderer renderer;
|
SparrowRenderer renderer;
|
||||||
QTimer openglRefreshTimer;
|
|
||||||
|
|
||||||
// camera handling variables
|
// camera handling variables
|
||||||
QPoint lastMousePos;
|
QPoint lastMousePos;
|
||||||
@ -29,6 +27,9 @@ class DrawWidget : public QOpenGLWidget
|
|||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
||||||
|
bool new_simulation;
|
||||||
|
bool update_needed;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Output
|
// Output
|
||||||
virtual void initializeGL();
|
virtual void initializeGL();
|
||||||
@ -47,6 +48,7 @@ class DrawWidget : public QOpenGLWidget
|
|||||||
~DrawWidget();
|
~DrawWidget();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void updateDudesBehavior();
|
||||||
void startSimulation(GenerateFunction, std::vector<BehaviorFunction>);
|
void startSimulation(GenerateFunction, std::vector<BehaviorFunction>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#define LIB_SUFFIX "dll"
|
#define LIB_SUFFIX "dll"
|
||||||
@ -31,6 +32,7 @@ void LibWidget::refreshBehaviors()
|
|||||||
{
|
{
|
||||||
while(ui->behaviorsList->count() > 0)
|
while(ui->behaviorsList->count() > 0)
|
||||||
ui->behaviorsList->takeItem(0);
|
ui->behaviorsList->takeItem(0);
|
||||||
|
m_behaviorList.clear();
|
||||||
QDir teamDir(QCoreApplication::applicationDirPath());
|
QDir teamDir(QCoreApplication::applicationDirPath());
|
||||||
if(teamDir.cd("../teams"))
|
if(teamDir.cd("../teams"))
|
||||||
{
|
{
|
||||||
@ -59,6 +61,7 @@ void LibWidget::refreshGenerators()
|
|||||||
{
|
{
|
||||||
while(ui->generatorsList->count() > 0)
|
while(ui->generatorsList->count() > 0)
|
||||||
ui->generatorsList->takeItem(0);
|
ui->generatorsList->takeItem(0);
|
||||||
|
m_genList.clear();
|
||||||
QDir genDir(QCoreApplication::applicationDirPath());
|
QDir genDir(QCoreApplication::applicationDirPath());
|
||||||
if(genDir.cd("../generators"))
|
if(genDir.cd("../generators"))
|
||||||
{
|
{
|
||||||
@ -81,13 +84,15 @@ void LibWidget::refreshGenerators()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
emit sendError(QString("ERROR : can't open the generators folder.\n"), 5000);
|
emit sendError(QString("ERROR : can't open the generators folder.\n"), 5000);
|
||||||
|
if(!m_genList.empty())
|
||||||
|
ui->generatorsList->item(0)->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibWidget::launchSimulation()
|
void LibWidget::launchSimulation()
|
||||||
{
|
{
|
||||||
GenerateFunction genFunc = m_genList[ui->generatorsList->currentRow()];
|
GenerateFunction genFunc = m_genList[ui->generatorsList->currentRow()];
|
||||||
std::vector<BehaviorFunction> behaveFuncs;
|
std::vector<BehaviorFunction> behaveFuncs;
|
||||||
for(QListWidgetItem *item : ui->generatorsList->selectedItems())
|
for(QListWidgetItem *item : ui->behaviorsList->selectedItems())
|
||||||
behaveFuncs.push_back(m_behaviorList[ui->behaviorsList->row(item)]);
|
behaveFuncs.push_back(m_behaviorList[ui->behaviorsList->row(item)]);
|
||||||
emit createSimulation(genFunc, behaveFuncs);
|
emit createSimulation(genFunc, behaveFuncs);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user