Browse Source

Add GLWidget

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
cb38464a28
6 changed files with 59 additions and 3 deletions
  1. +1
    -0
      include/rack.hpp
  2. +1
    -1
      include/widgets/FramebufferWidget.hpp
  3. +14
    -0
      include/widgets/GLWidget.hpp
  4. +4
    -2
      src/widgets/FramebufferWidget.cpp
  5. +34
    -0
      src/widgets/GLWidget.cpp
  6. +5
    -0
      src/window.cpp

+ 1
- 0
include/rack.hpp View File

@@ -19,6 +19,7 @@
#include "widgets/ZoomWidget.hpp"
#include "widgets/SVGWidget.hpp"
#include "widgets/FramebufferWidget.hpp"
#include "widgets/GLWidget.hpp"

#include "ui/SequentialLayout.hpp"
#include "ui/Label.hpp"


+ 1
- 1
include/widgets/FramebufferWidget.hpp View File

@@ -28,7 +28,7 @@ struct FramebufferWidget : Widget {
FramebufferWidget();
~FramebufferWidget();
void draw(NVGcontext *vg) override;
virtual void drawFramebuffer(NVGcontext *vg);
virtual void drawFramebuffer();
int getImageHandle();

void onZoom(const event::Zoom &e) override {


+ 14
- 0
include/widgets/GLWidget.hpp View File

@@ -0,0 +1,14 @@
#pragma once
#include "widgets/FramebufferWidget.hpp"


namespace rack {


struct GLWidget : FramebufferWidget {
void step() override;
void drawFramebuffer() override;
};


} // namespace rack

+ 4
- 2
src/widgets/FramebufferWidget.cpp View File

@@ -69,7 +69,7 @@ void FramebufferWidget::draw(NVGcontext *vg) {
return;

nvgluBindFramebuffer(fb);
drawFramebuffer(app()->window->fbVg);
drawFramebuffer();
nvgluBindFramebuffer(NULL);
}

@@ -101,7 +101,9 @@ void FramebufferWidget::draw(NVGcontext *vg) {
nvgRestore(vg);
}

void FramebufferWidget::drawFramebuffer(NVGcontext *vg) {
void FramebufferWidget::drawFramebuffer() {
NVGcontext *vg = app()->window->fbVg;

float pixelRatio = fbSize.x / fbBox.size.x;
nvgBeginFrame(vg, fbBox.size.x, fbBox.size.y, pixelRatio);



+ 34
- 0
src/widgets/GLWidget.cpp View File

@@ -0,0 +1,34 @@
#include "widgets/GLWidget.hpp"
#include "app.hpp"


namespace rack {


void GLWidget::step() {
// Render every frame
dirty = true;
}


void GLWidget::drawFramebuffer() {
glViewport(0.0, 0.0, fbSize.x, fbSize.y);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, fbSize.x, 0.0, fbSize.y, -1.0, 1.0);

glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex3f(0, 0, 0);
glColor3f(0, 1, 0);
glVertex3f(fbSize.x, 0, 0);
glColor3f(0, 0, 1);
glVertex3f(0, fbSize.y, 0);
glEnd();
}


} // namespace rack

+ 5
- 0
src/window.cpp View File

@@ -243,6 +243,11 @@ Window::Window() {
// GLEW generates GL error because it calls glGetString(GL_EXTENSIONS), we'll consume it here.
glGetError();

const GLubyte *renderer = glGetString(GL_RENDERER);
const GLubyte *version = glGetString(GL_VERSION);
INFO("Renderer: %s", renderer);
INFO("OpenGL: %s", version);

glfwSetWindowSizeLimits(win, 800, 600, GLFW_DONT_CARE, GLFW_DONT_CARE);

// Set up NanoVG


Loading…
Cancel
Save