Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • W weston
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 340
    • Issues 340
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 129
    • Merge requests 129
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • waylandwayland
  • weston
  • Issues
  • #487
Closed
Open
Issue created Apr 09, 2021 by Andre Osku Schmidt@oskude

cheapest blend

i want to draw/animate this thing:

  1. draw filled rectangle with dark transparent color, over the size of area
  2. draw filled rectangle with light transparent color, over the size of data
  3. wait and repeat (i don't need shorter wait time than ~250msec)

this example html/js thing shows exactly what i want:

<canvas width="128" height="32"></canvas>
<script>
const ctx = document.querySelector("canvas").getContext("2d")
setInterval(function(){
	ctx.fillStyle = "rgba(0, 0, 0, 0.2)"
	ctx.fillRect(0, 0, 128, 32)
	ctx.fillStyle = "rgba(0, 255, 0, 0.2)"
	for (let i = 0; i < 4; i++) {
		let r = Math.sin(Date.now()/1000+(1*i)) * 0.5 + 0.5
		ctx.fillRect(0, 0+((32/4)*i), 128*r, 32/4)
	}
}, 250)
</script>

ignore the maths and numbers, it's about fillStyle and fillRect, and how they blend with previous drawing. (you can save that to a file and open in any modern browser)

i was able to boil it down to this opengl/c code:

#include <GL/gl.h>
#include <GLFW/glfw3.h>
#include <unistd.h>
#include <math.h>

int main (void) {
	float s = 2.0 / 4;
	double t; int i;
	GLFWwindow* window;
	if (!glfwInit()) return 1;
	window = glfwCreateWindow(128, 32, "test", NULL, NULL);
	if (!window) { glfwTerminate(); return 2; }
	glfwMakeContextCurrent(window);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	while (1) {
		t = glfwGetTime();
		glColor4f(0, 0, 0, 0.2);
		glRectf(-1, -1, 1, 1);
		for (i = 0; i < 4; i++) {
			glColor4f(0, 1, 0, 0.2);
			glRectf(-1, -1+(s*i), sin(t+i), -1+(s*(i+1)));
		}
		glFlush();
		glfwSwapBuffers(window);
		usleep(1000 * 250);
	}
	return 0;
}

build with: gcc foo.c -o foo $(pkg-config --cflags --libs glfw3 gl) -lm

that opengl/c code renders the same as the html/js version, but only on x11 (openbox). on wayland with weston (or wayfire) the blending is "all bonkers", so i wonder...

  • why does that opengl/c code work on x11?
  • why does it not work the same on weston (wayland)? (or does it for you?)
  • or it should work, and the bug is somewhere (else)?
  • optional: what is the cheapest way to draw this on/for weston/wayland?

as i'm a total wayland/opengl/c noob (and mostly trial-and-error until something (seems) to work >.<*), i would be very thankful for any related/specific clarification (links) ❤

ps. i wonder if/when we get single buffer with glfw, if that's gonna solve the problem? https://github.com/glfw/glfw/issues/1843

Edited Apr 09, 2021 by Andre Osku Schmidt
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking