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