Skip to content

Commit

Permalink
add some more glitching to poly glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamPorcineFudgepuppy committed Jun 23, 2024
1 parent 272c47b commit 371f448
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ComputerscareGlolyPitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct ComputerscareGlolyPitchWidget : ModuleWidget {
glitchOpenGL->box.size = APP->window->getSize();
APP->scene->addChild(glitchOpenGL);

APP->window->screenshot(system::join("/Users/adammalone/Desktop", "screenshot.png"));

}
/* addChild(display);
Expand Down
68 changes: 66 additions & 2 deletions src/glitch/GlitchOpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,67 @@ struct GlitchOpenGLWidget : OpenGlWidget {
glClear(GL_COLOR_BUFFER_BIT);
}



void drawPixels(int width,int height) {
math::Vec fbSize = getFramebufferSize();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, fbSize.x, 0.0, fbSize.y, -1.0, 1.0);

/* void Window::screenshot(const std::string& screenshotPath) {
// Get window framebuffer size
int width, height;
glfwGetFramebufferSize(APP->window->win, &width, &height);
// Allocate pixel color buffer
uint8_t* pixels = new uint8_t[height * width * 4];
// glReadPixels defaults to GL_BACK, but the back-buffer is unstable, so use the front buffer (what the user sees)
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Write pixels to PNG
flipBitmap(pixels, width, height, 4);
stbi_write_png(screenshotPath.c_str(), width, height, 4, pixels, width * 4);
delete[] pixels;
}*/

int fbWidth, fbHeight;
glfwGetFramebufferSize(APP->window->win, &fbWidth, &fbHeight);

uint8_t* fbPixels = new uint8_t[width * height * 4];


// glReadPixels defaults to GL_BACK, but the back-buffer is unstable, so use the front buffer (what the user sees)


glReadBuffer(GL_FRONT);
glReadPixels(300, 200, width, height, GL_RGBA, GL_UNSIGNED_BYTE, fbPixels);

//unsigned char pixels[width * height * 3];
// memset(pixels, 0, sizeof(pixels)); // Clear to black
uint8_t* pixels = new uint8_t[height * width * 4];
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; ++j) {
pixels[(i * height + j) * 4 + 0] = 255*random::uniform(); // Red component
pixels[(i * height + j) * 4 + 1] = 127*random::uniform(); // Green component
pixels[(i * height + j) * 4 + 2] = 0; // Blue component
pixels[(i * height + j) * 4 + 3] = 255*random::uniform(); // Alpha component
}
}
glRasterPos2i(fbWidth*random::uniform(), fbWidth*random::uniform()); // Start drawing at position (0, 0)
if(random::uniform() < 0.5) {
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
} else {
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, fbPixels);
}

delete[] pixels;
delete [] fbPixels;
}

void drawFramebuffer() {
math::Vec fbSize = getFramebufferSize();
glViewport(0.0, 0.0, fbSize.x, fbSize.y);
Expand All @@ -47,7 +108,7 @@ struct GlitchOpenGLWidget : OpenGlWidget {
}


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

Expand All @@ -61,7 +122,10 @@ struct GlitchOpenGLWidget : OpenGlWidget {
glEnd();
if(random::uniform() < 0.8) {
clearRandomRect();
}
}
if(random::uniform() < 0.9) {
drawPixels((int) 1000*random::uniform(), (int) 1000*random::uniform());
}

}

Expand Down

0 comments on commit 371f448

Please sign in to comment.