fixed sorting, wont use qpainter(this), need to use pixmap with texture sampling

main
Benjamin Kraft 1 year ago
parent c2f109e6a8
commit 71474f3cb6
  1. 5
      shaders/fragment.glsl
  2. 6
      shaders/vertex.glsl
  3. 22
      src/GLWidget.cpp
  4. 10
      src/main.cpp

@ -4,10 +4,10 @@ out vec4 FragColor;
in vec3 color;
uniform bool drawPoints;
uniform bool drawPoints = false;
void main() {
if (drawPoints){
if (drawPoints == true){
vec2 coord = gl_PointCoord - vec2(0.5);
if (length(coord) > 0.5)
discard;
@ -18,5 +18,4 @@ void main() {
} else {
FragColor = vec4(color, 1);
}
}

@ -6,7 +6,7 @@ layout (location = 2) in float vMassRadius;
uniform mat3 VP;
uniform bool drawPoints;
uniform bool drawPoints = false;
uniform float screenSizePixels;
uniform float screenSizeMeters;
uniform float depthOffset;
@ -14,9 +14,9 @@ uniform float depthOffset;
out vec3 color;
void main() {
if (drawPoints){
if (drawPoints == true){
gl_Position = vec4(VP * vPos, 1.0);
gl_Position.z -= depthOffset * 0.25;
gl_Position.z -= depthOffset * 0.5;
gl_PointSize = vMassRadius / screenSizeMeters * screenSizePixels * 2;
} else {
gl_Position = vec4(VP * vPos, 1.0);

@ -37,7 +37,7 @@ void GLWidget::initializeGL() {
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glClearDepth(1);
glClearColor(.15, .15, .15, 1);
std::vector<Pendulum*> empty;
@ -45,12 +45,12 @@ void GLWidget::initializeGL() {
}
void GLWidget::paintGL() {
auto p = new QPainter(this);
p->setRenderHint(QPainter::Antialiasing);
p->beginNativePainting();
QPixmap img(size());
auto p = new QPainter(&img);
// Native OpenGL
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
program->bind();
@ -75,7 +75,6 @@ void GLWidget::paintGL() {
glBindVertexArray(0);
}
p->endNativePainting();
// FPS
{
@ -105,7 +104,7 @@ bool GLWidget::AnyDialogOpen() {
void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) {
int segmentCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){
int pointCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){
return prev + curr + 1;
}, [](const Pendulum * p){
return p->X.size();
@ -118,8 +117,9 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) {
if (!pendula->empty()){
float depth = 1.f - 1.f / float(segmentCount);
depthOffset = 1.f * 2 / float(segmentCount);
float margin = 0.1f;
depthOffset = 2 * (1.f - margin) / float(pointCount);
float depth = (1.f - margin) - (1.f - margin) / float(pointCount) + depthOffset;
GLuint index = 0;
for (const auto p : *pendula){
@ -127,8 +127,7 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) {
// Origin point
positions.push_back(0);
positions.push_back(0);
positions.push_back(depth);
depth -= depthOffset;
positions.push_back(depth -= depthOffset);
colors.resize(colors.size() + 3);
float * red = &colors.back() - 2;
@ -143,8 +142,7 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) {
Vector pos = p->X[segment];
positions.push_back(float(pos.x));
positions.push_back(float(pos.y));
positions.push_back(depth);
depth -= depthOffset;
positions.push_back(depth -= depthOffset);
colors.resize(colors.size() + 3);
red = &colors.back() - 2;

@ -8,15 +8,15 @@
using namespace std::chrono;
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QSurfaceFormat fmt;
fmt.setSamples(4);
fmt.setDepthBufferSize(24);
//fmt.setVersion(3, 3);
//fmt.setProfile(QSurfaceFormat::CoreProfile);
fmt.setDepthBufferSize(32);
fmt.setVersion(3, 3);
fmt.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(fmt);
QApplication app(argc, argv);
MainWindow w;
w.show();

Loading…
Cancel
Save