Are point sprites always perfect circles/squares? - opengl-es-2.0

I noticed that regardless of the shape (aspect ratio) of a texture, it will always draw as a perfect square, scaling unequally, when using it as a point sprite. I assume this is because points are, after all, circular.
If you wish to use point sprites on rectangular textures, is this possible using the point sprite mechanism, or would I need to just build quads with textures instead?
Or perhaps there is something that can be added to a shader to recognize and work with a rectangular texture? Currently mine are quite simple:
Vertex shader:
TextureCoordOut = TextureCoordinate;
gl_PointSize = 15.0;
Fragment:
gl_FragColor = texture2D(Sampler, isSprite? gl_PointCoord: TextureCoordOut) * DestinationColor;

Points have only one size, which will be equally applied to the width and height..

Related

How to draw a round point in vulkan?

I'm able to render a point in vulkan by specifying VK_PRIMITIVE_TOPOLOGY_POINT_LIST in the graphics pipeline. But the resulting point is a small square.
How can I draw a round point in Vulkan? Is there an equivalent to GL_SMOOTH_POINT?
As noted in the comments, there is no such functionality built-into Vulkan.
But you can easily emulate this in your point list rendering fragment shader by discarding fragments outside of a given circular radius like this:
const float radius = 0.25;
if (length(gl_PointCoord - vec2(0.5)) > radius) {
discard;
}

More vertices for circles

I just added a sprite-circle to a 2D-Game with physics. I just realized that the circle has only very few vertices. Can I increase the vertex count of the circle by using GUI only?
I am using the LTS 2020.3.29f1 version of Unity
A sprite does not have vertices, it has pixels.
You can use a higher resolution texture if you wish to make the sprite look better when scaled up.
If your concern is accuracy of the collider's hitbox, then you can't do better than the CircleCollider2D as it has effectively infinite resolution in respect to a perfect circle.

Parallax effect jitter in libGDX

Basically I'm using this ParallaxCamera class to create the effect in my game, but upon movement, the layers "wiggle". This is especially noticeable when the camera is moving slowly.
I have fixed the timestep and use interpolated smoothing. I use scaled up pixel art. Camera centered on player, updated after movement. Disabling the effect makes moving the camera smooth.
What I guess the issues might be:
the layers move at different paces which means they move at different
times
rounding to display makes the layers assume slightly different positions each frame when moving the camera
Thanks for any help
For low-resolution pixel art, this is the strategy I've used. I draw to a small FrameBuffer at 1:1 resolution and then draw that to the screen. That should take care of jittering.
If your Stage is also at the same resolution, then you have to use a bit of a hack to get input to be processed properly. The one I've used it to use a StretchViewport, but I manually calculate the world width and height to not stretch the world, so I'm basically doing the same calculation that ExtendViewport does behind the scenes. You also have to round to an integer for the width and height. You should do this in resize and apply the width and height using viewport.setWorldWidth() and setWorldHeight(). So in this case it doesn't matter what world size you give to the constructor since it will be changed in update().
When you call update on the viewport in resize, you need to do it within the context of the FrameBuffer you are drawing to. Otherwise it will mess up the screen's frame buffer dimensions.
public void resize(int width, int height) {
int worldWidth = Math.round((float)WORLD_HEIGHT / (float)height * (float)width);
viewport.setWorldWidth(worldWidth);
viewport.setWorldHeight(worldHeight);
frameBuffer.begin();
viewport.update(width, height, true); // the actual screen dimensions
frameBuffer.end();
}
You can look up examples of using FrameBuffer in LibGDX. You should do all your game drawing in between frameBuffer.begin() and end(), and then draw the frameBuffer's color buffer to the screen like this:
stage.act();
frameBuffer.begin();
//Draw game
stage.draw();
frameBuffer.end();
spriteBatch.setProjectionMatrix(spriteBatch.getProjectionMatrix().idt());
spriteBatch.begin();
spriteBatch.draw(frameBuffer.getColorBufferTexture(), -1, 1, 2, -2);
spriteBatch.end();
In my case, I do a more complicated calculation of world width and world height such that they are a whole number factor of the actual screen dimensions. This prevents the big pixels from being different sizes on the screen, which might look bad. Alternatively, you can change the filtering of the FrameBuffer's texture to linear and use an upscaling shader when drawing it.

OpenGL drawing with mouse

If I try to texture drawing line with loaded texture
glLineWidth(10);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, brushTextura);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINES);
glVertex2f(location.x, location.y);
glVertex2f(prevLocation.x, prevLocation.y);
glEnd();
glFlush();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
It draws nothing. When I use same code, but drawing not GL_LINES, but GL_POINTS everything works as it should work. Image link here.
If i don't use texture here, and use GL_LINES, it draws lines as it should, but its not looking good. Image link here. Any solutions for drawing nice, smooth textured lines?
A line will not "magically" use the texture as kind of a brush applied along the path of the line. You'd actually have to supply some texture coordinates, but those would then only take slices out of the texture and not apply it as a "brush".
If points work for you, only if point sprites are enabled, because a point would sample only a single texure pixel and spread it over its whole area.
Honestly, I think your whole attempt is flawed. Usually when drawing with brushed, you draw it as a large number of textured quads at a regular, small distance.

Simple polygon texture mapping / iOS / cocos2d

I got some problems with opengl and cocos2d. I suck with opengl i know. I was trying to find just a simple answer but no luck.
What I'm trying to do is to map a texture like this:
... so i got points
CGPoint points[4];
points[0] = ccp(x1,y1);
points[1] = ccp(x2,y2);
points[2] = ccp(x3,y3);
points[3] = ccp(x4,y4);
Whats next :( ?
All I want to do is map that texture on that polygon.
I will show it in "idiot" way :)
Firstly I would design the texture with the bottom horizontal and then rotate the sprite at the end, as this makes it a whole lot easier.
I would load the texture into a UIImage. Then use CGContexts to remove the triangular portions in the top corners.
Then load that UIImage into a CCTexture2D which I would then create a sprite from. Then rotate the sprite, so that it is at the required orientation.
Alternatively, if you don't need the texture to be generated programmatically you could just remove the corners from the texture, using gimp, photoshop or pixelmator. Then just load that texture the same way you would load any other.