I'm developing little game based on LWJGL (so Java). I'm rendering skybox (that darkblue somthing on image), that is constructed from 6 quads (GL_QUADS) and one box (white something), that is rendered using VBO.
Problem is, that white box is glitching (geometry is OK, but image in framebuffer is...). I dunno, how to find reason (depth testing, alpha, ...) I've tried someting (render ordering), but nothing helps.
Is render order important for objects, that are solid (opaque)?
It's typical. Lastly I tried to disabling features in renderer.
glEnable(GL_DEPTH_TEST);
This was that beast.... tfuj - I'm sorry for spam.
It looks like your box is too close to camera so it is cut buy near clip plane. Try decreasing the nearVal of glFrustum.
Related
Hello I would like to know how I can clip off part of a texture that overlaps with another texture. Like the image below but without rendering part of the overlapped white "X". The octagon has an alpha transparency, i want to be able to see every thing under it except part of the overlapped white X.
Maybe this can help you
libgdx open gles 2.0 stencil alpha masking
It Looks like you Need to use a mask..
Another link, where I had my own Problem, where I used a depth buffer would be this here:
https://gamedev.stackexchange.com/questions/119821/libgdx-shaperender-within-a-circle-as-limitter/119869#119869
I hope this will help you furthermore.
I am trying to write a card game, that will have an image in the middle, a coloured border and potentially a symbol in the top left. I am using libgdx and a stage/scene2d.
The image will change depending on the suit (these are not your normal 52 deck type of cards), the border colour will change to match the suit, though this colour can be pre determined by the user so I can't pre-save coloured images (though I guess I could pre save about 15 diff colours and give the user a choice of 15) and the symbol will only be on some cards and not others.
As you can see from the two images I've added I have two diff images, border colours and symbols.
My question is relating to groups and overdraw.
1) I presume I should set up a group with 3 images in, and I'm hoping having this won't slow my game down as I will have potentially 30 cards on screen at once and 30 groups with up to 3 images in each could be a lot to draw. Is this right and will LibGDX be able to handle it fine?
2) How should I do the coloured border? Should I have the entire card a coloured rectangle and the image drawn on top? Would the draw method be trying to draw the coloured section underneath the image and thus wasting GPU/CPU time? A friend of mine said I could just have a white image, and then set the colour using RGB values in the code? Is this possible? That would mean I could only have a single jpg which would be much better for apk size.
3) Or should I ignore using a jpg image and try and draw the coloured square using ShapeRenderer?
Thanks, I hope these questions aren't too many in one post.
Of course it will not slow you game - 90 (30 groups x 3 textures) sprites on screen are like nothing for (I guess) every framework - so LibGDX will do the thing also.
Although it does matter how these graphics will be stored! Please use one TextureAtlas with all textures instead of many textures in many files - you can prepare the Atlas by using TexturePacker (for a basic usage like this free version will be ok).
The reason of this is that if you are using many single Textures LibGDX needs to switch graphic in GPU bufor (maybe it is not perfect term) before rendering each of them - if you have one big texture (including others) it does not need to switch anything because nothing changes in the buffor.
To get more information about using TextureAtlas take a look at the manual
Yes you can "color" the Actor (like Image) by using for example
actor.addAction(Actions.color(new Color(1f,1f,1f, 0.2f), 2f));
another approach is to have 1px x 1px texture of every color (packed in your Texture Atlas) and just to change it's size. There no reason to keep full size singe-colour textures since it is great vaste of space and memory.
It is generally not good idea to use ShapeRenderer - of course it is helpful sometimes but drawing sprites has a greater performance.
You are generally a little bit too scared about performance but if you want to save your CPU avoiding ShapeRenderer seems to be good idea.
I was searching for an anti-aliasing algorithm for my OpenGL program (so I searched for a good shader). The thing is, all shaders want to do something with the textures, but I dont use textures, only colors. I looked at FXAA most of the time, so is there a anti-aliasing algorithm that just works with colors? My game, what this is for looks blocky like minecraft, but only works with colors and cubes of different size.
I hope someone can help me.
Greetings
Anti-aliasing has nothing specifically to do with either textures or colors.
Proper anti-aliasing is about sample rate, which while highly technical can be thought of as doing extra work to make a better educated guess at some value that cannot be directly looked up (e.g. a pixel that is only partially covered by a triangle).
Multisample Anti-Aliasing (MSAA) will work nicely for you, it will only anti-alias polygon edges and does nothing for texture aliasing on the interior of a polygon. Since you are not using textures you do not need to worry about aliasing inside a polygon.
Incidentally, FXAA is not proper anti-aliasing. FXAA is basically a shader-based edge detection and blur image processing filter. FXAA will blur any part of the scene with sharp edges, whether it is a polygon edge or an edge due to a mapped texture. It indiscriminately blurs anything it thinks is an aliased edge and gets this wrong often, resulting in blurry textures.
To use MSAA, you need:
A framebuffer with at least 2 samples
Enable multisample rasterization
Satisfying (1) is going to depend on what you used to create your window (in this case LWJGL). Most frameworks let you select the sample count as one of the parameters at the time of creation.
Framebuffer Objects can also be used to do this without messing with your window's parameters, but they are more complicated than need be for this discussion.
(2) is as simple as calling glEnable (GL_MULTISAMPLE).
I'm developing an Android game using Java, and I am currently on trying to figure out an efficient way of rendering the necessary textures. Suppose you have a Grid, similar to a Checkers board layout, and Tiles to fill that grid, as in each square on the board. That is the concept of what will be displayed. Currently, I am drawing each tile one by one. All of the texture loading is done upon creation and is only done once, not upon drawing. Now, for what I want to do. I've noticed that drawing all one by one, although fast for what I'm doing, it can be glitchy. In my game, the user has the ability to drag the "board" to view different areas. As of right now, I'm only allowing the necessary tiles to be drawn depending on the location of the top left visible tile. As I said, it works quite fast, but, once the user starts interacting more or dragging faster, the rendering starts to have difficulties and isn't as fast as it should be. This causes little separation in between the tiles. It's not large, just large enough to be noticeable. What I want to do is to basically place each texture in a certain location as defined by the grid, thus creating a new texture containing the viewable area, and then render that entire area as opposed to render each tile separately. I've done a lot of research and already looked at many questions, but I still have not found something that will help my cause. I've read that rendering to texture using a framebuffer may help, but I haven't found any easy-to-follow tutorials or examples, just a lot "here's the code, no explanation" or "here's something similar to what you want, but it's using different things." So, if someone could point me towards a good tutorial/example, or post a valuable answer, I would be very grateful. I'm avoiding OpenGL ES 2.0 because I want my game to be compatible with many devices, and for what I'm doing, 2.0 is not necessary.
For a quick summary of what my code does for further explanation:
for(go through visible rows){
for(go through visible columns){
drawTile(); //Does the texture binding and drawing for each tile
}
}
What I want:
for(go through visible rows){
for(go through visible columns){
loadTileTextureIntoGridTexture();
//I want it to combine the textures into one texture
}
}
drawGridTexture();
Doing it the second way will only have one whole texture to render as opposed to visibleRows*visibleColumns textures to render.
I've googled around everywhere, but cannot find much for rendering strings to textures and then displaying that texture on a quad on the screen. Can someone provide a run-down on the process or provide good resources that describe how? Is rendering strings to textures even the best method for displaying text in an Android OpenGL ES app?
EDIT:
Okay, so LabelMaker interferes with alpha blending, the texture (created from a PNG with a transparent background) now has a solid black background, rather than a transparent background. If I comment out all the LabelMaker-related code, it works fine.
UPDATE:
Nevermind. I took a look at the code to find that LabelMaker was disabling blending after drawing the labels.
I think this is what you are looking for.
If you don't want to use GL extensions you need to create the font as a bitmap and then create a class to convert that string into quads that you can draw.
I use this method with the 2 fonts in my game. I have a class that takes a wide texture with all the letters evenly spaced, and a string that matches the image, then uses lookups on the letters to find out how far in the bitmap it should go.
Your other option is to render your text to a offscreen bitmap using android, and then bind the text as a texture. This will let you use androids built-in font processing and rendering to create texture-based fonts.
The second method I have not used yet, but I have rendered google maps to a offscreen canvas and then bound the bitmap as a GL texture, so doing it for text should be much simpler.
If you are planning to have modifying string data in a gl loop you need to really worry about StringBuilder too, because it causes GC and performance issues. I hardcode all my strings so it doesn't allocate, and all my rapidly numbers are done through a second draw function dedicated to drawing changing numbers without using string-builder.