Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glob2 renders a white square instead of semi-transparent building when placing a school #124

Open
Quipyowert2 opened this issue Jan 2, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Quipyowert2
Copy link
Contributor

Quipyowert2 commented Jan 2, 2025

When I start tutorial 4 and start to place a school in a spot where there is already a building, the game shows a white square with a red outline instead of a semi-transparent building indicator like when placing a hospital. Happens with commit c196fa5. This is probably my fault. I think the bug is from my PR #120.

Please disregard the tutorial messages in the screenshots, the "A unique string" is from when I was testing something.

semi-transparent hospital on swarm
missing image when placing school on swarm

@stephanemagnenat
Copy link
Contributor

stephanemagnenat commented Jan 3, 2025

Hum, it feels to me like the per-object-draw transparency is not correct when using the new drawing path. I do not have the full new drawing code in mind, but I feel that somehow the transparency of each draw should be stored somewhere and used in the shader when drawing each object, even from the same sprite sheet.

@Quipyowert2
Copy link
Contributor Author

Quipyowert2 commented Jan 4, 2025

Looks like I need to somehow pass the transparency values to glDrawArrays instead of falling back to the slow path (glBegin/glEnd) when the sprite is being drawn with transparency. From a quick search, it looks like this can be done with vertex array objects or maybe shaders? I will have to look up how to do that when I have time, hopefully in the next few days.

@stephanemagnenat
Copy link
Contributor

In Candli I'm doing something similar using a simple pair af vertex/fragment shaders. But it is in WebGL so the setup API calls differ a bit. I can copy/paste the shaders here if that is helpfu (later, I'm on mobile now)l, although they might need some adaptation for OpenGL 2.

@stephanemagnenat
Copy link
Contributor

stephanemagnenat commented Jan 5, 2025

Here are the Candli object shaders for WebGL 1.0 (based on OpenGL ES 2.0 API):

Vertex

attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;

uniform mat3 uWorldToViewport;
uniform mat3 uPoseToWorld;

varying lowp vec2 vTextureCoord;

void main() {
	gl_Position = vec4(uWorldToViewport * uPoseToWorld * vec3(aVertexPosition, 1.0), 1.0);
	vTextureCoord = aTextureCoord;
}

In Glob2 you might not need both uWorldToViewport and uPoseToWorld.

Fragment

varying lowp vec2 vTextureCoord;

uniform sampler2D uSampler;
precision lowp float;
uniform float uAlpha;

void main(void) {
	vec4 col = texture2D(uSampler, vTextureCoord);
	col.rgba *= uAlpha;
	gl_FragColor = col;
}

Hopefully these can serve as a helpful inspiration, uAlpha allows for per draw alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants