I wrote some code to load a .obj file one triangle at a time in 3d. Each of these triangles are placed in the correct location, and are given a random color. When the full shape is loaded some triangles, even though they are placed in front of the others, go to the back and are not seen.
http://postimg.org/image/ln31rhabd/
The website above shows how the triangles Behind the cone are showing up OVER the ones in-front. the cone is being looked at from a top-front angle.
What do I have to do to make the ones on top actually show up on top? Do they stack in the order that each triangle was created?
At the outset, i believe the problem is related to Depth Buffering.
Try enabling z-buffering in by calling the following functions:
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
And also, do check if you are clearing the z-buffers along with the color buffers.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Related
I apologize for some of my ignorance as I am fairly new to Slick2D and LWJGL. Essentially what I'm trying to do is make a scene look like night time by covering it with a GL_QUADS rectangle that is tinted blue and is translucent.
That part is easy enough. What I want to do from there is draw triangles into this layer that vary the alpha channel so. The reason I want to do this is so I can simulate a light source by decreasing the opacity of the blue tinted rectangle as it gets closer to the light source.
I drew an example of what the expected result should be with the green being the background, the blue being the nighttime effect created by a blue tinted rectangle, and the increasingly dim light source in the center.
I need to find a way to do this with triangles because I created a raycasting algorithm that generates the result as a series of gradient triangles.
I apologize if this is explained poorly. I will answer any questions you might have.
Here is the chunk of code used to create the blue tinted rectangle:
glColor4f (0.0f,0.0f,1.0f,0.4f);
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(screenWidth,0);
glVertex2f(screenWidth,screenHeight);
glVertex2f(0,screenHeight);
glEnd();
I would like to write a modified version of the following code to adjusted the alpha channel of that rectangle.
glBegin(GL_TRIANGLES);
setAlphaOfPriorLayer(0.0f);
glVertex2f(x1,y1);
setAlphaOfPriorLayer(0.4f);
glVertex2f(x2,y2);
setAlphaOfPriorLayer(0.4f);
glVertex2f(x3,y3);
glEnd();
Again, I'm using triangles to approximate a circle and allow for proper raycasting.
To achieve this, the use of a Frame Buffer Object is super useful. A FBO allows you to essentially render to a texture which can then be displayed on the screen. In my particular case, I rendered the elements to a FBO then used a shader while drawing it to the screen to get the desired opacities.
I'm not sure if this question is appropriate for this site. I figured this would be the best place to ask. I need to draw 15+ circles on the screen and translate/move each of them per frame. I don't know whether I should use vertices to draw the circle, or simply draw a square and attach an image of a circle on it. I thought it would be more practical/professional to use vertices but I then thought it might be a lot to handle. If each circle had 1000 points(so its smooth), that means each circle has 1002 vertices. 15 of those make 15,030 vertices I'm multiplying by a model matrix per frame. I figured that would be a lot for a device to handle. So then I thought about simply a square with 5 vertices(using a triangle strip) and just attaching a circle image as a texture. This would only make for 75 vertices to update per frame - a lot less. I also would be guaranteed to have a smooth looking circle. I just feel like this way isn't as professional. So I came here hoping for people with experience. Which method should I use for drawing circles? Vertices or Texture mapping? Or another method perhaps? Again, I apologize if this is a dumb question or if it has already been asked.
I'm developing 2D Side Scroll Android Game, using AndEngine.
I have problem with tiles quality.
If I will use DEFAULT texture option, for my texture congaing tiles, it doesn't look perfect, contours ARE NOT smooth, etc:
DEFAULT Texture options, uses such OPEN GL parameters:
new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, true);
But lately I realized, that if I will use such parameters (similar to BILINEAR parameters, except last one)
new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, true)
graphic looks smooth (i would say perfect, check image below)
Everything would be perfect, but while moving camera (Camera is chasing player) there are visible contours of those sprites, like for example on this screen:
I have been trying to use different OPEN GL parameters, but with no luck. I would be grateful for some help. With DEFAULT texture option, such problem doesn't exist, but quality is bad. Thanks.
Ps: I have been trying to cast integer on my setCenter method inside camera, but with no luck, some people were saying it should help, but it didn't.
This occurs because the function that is used for smoothing out the textures uses pixels that are outside of the pictures on the Texture Atlas. These are black by default so the pixels on the edges are poisoned by the black area outside.
I have temporarily fixed the issue by extending the picture an all sides by 1px and putting there a copy of the adjacent 1px line from the picture. Then I set my TextureRegion to contain only the middle of the picture with the padding being outside. The results are probably not perfect but the lines are no longer noticeable.
I have seen someone on the AndEngine forums say that in the newest version the problem is fixed, so you may try updating.
Simple question that i've always pondered about. When I first got into opengl I had to find a way to draw "tiles" or a bunch of triangles with 1 opengl draw call to improve performance vastly. I did that by putting all the vertices into an array and drawing the array. One problem that occurred was whenever I scrolled the tiles, I would see random placed pixels showing on and off depending on how much I scrolled the map. Around 5-8 on a 10x10 map. Now, I got back into opengl again and and this time I drew using GL_LINE_LOOP instead of GL_TRiANGLES. This never occurred to me back then but what I see when using GL_LINE_LOOP is all the triangles but when it finishes(it goes from bottom left to top right, so top right) there is a line connecting where I ended and where I began. Would the cause of those random pixels be because of this? Or does this have nothing to do with it. Does that line connecting the end and beginning appear because of GL_LINE_LOOP mode or does that also have nothing to do with and have to do with the way I created the map?
GL_LINE_LOOP is a completely different drawing mode - and no that won't be the reason why you're dropping pixels on tiles.
Most likely reason for dropping pixels when drawing a tight mesh of tiles is that you're not computing the vertices consistently. The principle is that if a vertex is shared by two adjacent triangles (or quads, lines, whatever), then the floating point coordinates of that vertex must be 100% identical for every draw call. If you do that, then you're guaranteed to render a tight mesh without any gaps in between tiles.
Your problem may have been something else though... perhaps Z fighting.. but my guess is the first thing I mention here.
I'm new to OpenGL. I'm using JOGL.
I would like to create a sky for my world that I can texture with clouds or stars. I'm not sure what the best way to do this is. My first instinct is to make a really big sphere with quadric orientation GLU_INSIDE, and texture that. Is there a better way?
A skybox is a pretty good way to go. You'll want to use a cube map for this. Basically, you render a cube around the camera and map a texture onto the inside of each face of the cube. I believe OpenGL may include this in its fixed function pipeline, but in case you're taking the shader approach (fixed function is deprecated anyway), you'll want to use cube map samplers (samplerCUBE in Cg, not sure about GLSL). When drawing the cube map, you also want to remove translation from the modelview matrix but keep the rotation (this causes the skybox to "follow" the camera but allows you to look around at different parts of the sky).
The best thing to do is actually draw the cube map after drawing all opaque objects. This may seem strange because by default the sky will block other objects, but you use the following trick (if using shaders) to avoid this: when writing the final output position in the vertex shader, instead of writing out .xyzw, write .xyww. This will force the sky to the far plane which causes it to be behind everything. The advantage to this is that there is absolutely 0 overdraw!
Yes.
Making a really big sphere has two major problems. First, you may encounter problems with clipping. The sky may disappear if it is outside of your far clipping distance. Additionally, objects that enter your sky box from a distance will visually pass through a very solid wall. Second, you are wasting a lot of polygons(and a lot of pain) for a very simple effect.
Most people actually use a small cube(Hence the name "Sky box"). You need to render the cube in the pre-pass with depth testing turned off. Thus, all objects will render on top of the cube regardless of their actual distance to you. Just make sure that the length of a side is greater than twice your near clipping distance, and you should be fine.
Spheres are nice to handle as they easily avoid distortions, corners etc. , which may be visible in some situations. Another possibility is a cylinder.
For a really high quality sky you can make a sky lighting simulation, setting the sphere colors depending on the time (=> sun position!) and direction, and add some clouds as 3D objects between the sky sphere and the view position.