Tag Info

New answers tagged

0

From what I read from the shaders the light is in world-space and the light calculation is done on the object in part in untransformed object-space. You need to compute your lighting with both light & model in world-space or both in camera space. Whenever moving the camera messes up the lighting it means some of the data is calculated in a different ...


3

(I'm adding this here due to the the fact that ChrisE's answer is highly ambiguous, which is unfortunately due to the ambiguity of the original question. However I'm going to assume the OP's question should have been titled "when to use VAOs and when to use VBOs".) Vertex Buffer Objects (which really aren't dissimilar from other types of Buffer Objects, for ...


0

change int[] indices = new int[(TILES_WIDE * 6 * TILES_HIGH) - ((TILES_WIDE + 1) * 6)]; to int[] indices = new int[((TILES_WIDE-1) * 6 * (TILES_HIGH-1)]; And then a proper x,y iteration over (TILES_WIDE-1), (TILES_HIGH-1) to set the indices.


0

Make sure you request a depth buffer from LWJGL by passing a PixelFormat to your call of Display.create. Like so: Display.create(new PixelFormat(4,24,0,4)); The 24 indicates a 24 bit depth buffer.


4

Your main question seems to be: What would be the best way to draw frequently (really frequently, basically every frame) changing geometry with modern OpenGL? In most ways, there's no big difference between 2d and 3d OpenGL. The graphics pipeline has that one extra coordinate, Z, which won't be used as much in 2d, but that's about it. There's a few ...


1

The issue was with the loading. I'm not sure what exactly the problem was, because I changed the code significantly, but it's working now. EDIT Current loading code: GLuint getShaders(const char *vertexpath, const char *fragmentpath) { printf("****************** Loading Shaders ******************\nVertex: %s\nFragment: %s\n\n", vertexpath, fragmentpath); ...


4

I can't say to be expert of this subject, and in my game project(s) I have concentrated more on 3D side, so my 2D side is pretty simple generally using things made for 3D side; and obviously, my perspective is at gaming side, so my 2D graphics is more about blitting sprites than geometry. From that perspective, 1) Squares and rectangles are pretty easy. I ...


0

The short answer: Does it looks good enough? Yes - Keep it. No - Fiddle with it some more. Long answer: Getting accurate realistic physical based shading requires more GPU power than is possible, you'll always have to resort to faking things for the simple reason that a computer cannot simulate the entire universe, not even the entire visible light ...


2

This isn't a trivial task for someone new to graphics programming, I'm assuming you know how to write fragment shaders and sample textures. To convert the Bayer image to an RGB texture you'll want to point sample the monochrome Bayer image, and do the interpolation in the fragment shader. For each destination pixel, you'll know the value of one channel - ...


1

I found a great resource for comparing what specific APIs are available across different versions of OpenGL/WebGL/OpenGL ES. I think you will find what you are looking for, here: http://web.eecs.umich.edu/~sugih/courses/eecs487/common/notes/APITables.xml


0

To my knowledge of GLFW documentation and internals, events should only be dispatched in response to calls to PollEvents/WaitEvents. GLFW2 used to PollEvents in SwapBuffers, but that is gone in GLFW3. In any way, there's two possible solutions to your problem: Register your callbacks in the main loop, predicated on a boolean to ensure you do it once. ...


5

No. You can use the GL_QUADS primitive type instead of GL_TRIANGLES and draw four vertices instead of three. But even with this, OpenGL will internally render with triangles.


1

just append the data and adjust the indices: if the hilt has X vertices and the blade has Y then you first put the X vertices of the hilt and then put the vertices of the blade. Do the same for the indices but add X to each index of the blade. This will then force you to use only a single texture for the entire model.


0

Here is an excellent tutorial on texturing. :)


-2

I recommend switching to LWJGL. The best thing is, all your Opengl knowledge can carry over. They have extensive forums and a decent wiki. It makes using Opengl a lot easier.


2

It depends on the implementation of the multiply operation. The internals will suppose an ordering within your matrices, row major or column major. If the ordering of your matrices is arranged the way the function expects them, then it is up to the second dpendancy: namely the respect of the correct mathematical commutativity. (which they should) When you ...


2

SFML 2.0+ makes it even easier to load a texture; sf::Texture texLid; std::string image2="images/top.jpg"; if (!texLid.loadFromFile(image2)) { std::cout << "Could not load" << image2; char c; std::cin>>c; return false; } glEnable(GL_TEXTURE_2D);//tell OpenGL to use textures when drawing ...


1

You can use instancing and a texture atlas to combine all the draw calls into a single one. You only have a single 4 vertex VBO with the 4 corners 0,0 0,1 1,1 1,0 and an index buffer to draw them using GL_TRIANGLES. Then in a separate VBO you have the position and size of the quad (in a single vec4) and the position and size of the texture to use in the ...


7

Not really. Use vertex buffer objects. There can be perfectly efficient for large numbers of small triangles. The thing is that you don't want to make one VBO per quad, but rather few VBOs into which you stuff multiple quads.


1

I had forgotten to ask for a depth buffer when creating my window: Before: Display.create(new PixelFormat(4,0,0,4)); After Display.create(new PixelFormat(4,24,0,4));


1

It seems like you're confused about what constitutes a ray, which is a point with direction. Put another way, it's half of an infinite line. Here's an example: struct ray { vec3 origin; vec3 direction; }; Setting a ray to point in the direction of your camera would look like this ray.origin = camera.position; ray.direction = camera.forward; ...


2

Rather than using a geometry shader as mentioned in another answer, I managed to implement the lines very cleanly in the fragment shader, by passing the spherical coordinates before the deformation from the tessellation shader to the fragment shader. There I could then use uniforms that describe the number of level curves to calculate position and line width ...


0

Write your own botnet. I faced the same problem of not being able to test if shaders even compiled and linked on GLSL implementations and it drove me to a crude solution. I made small tools that ran in the background on a machine, waiting for JSON bundles with shaders sources to compile and link together using a windowless OpenGL context, returning the ...


1

You can use a geometry shader to generate those lines. There are a few tutorials/examples on how to generate sprites with geometry shaders, you can base yourself off of these to create thick lines with triangle strips from line strips. http://www.geeks3d.com/20140815/particle-billboarding-with-the-geometry-shader-glsl/


0

The problem is probably: precision lowp float; Which causes u_time to be 8bit unsigned fixed points with a range of only 0 to 1 or -2 to 2. setting it to mediump would probably fix the scrolling issue but would still degrade performance greatly. uniform mediump vec2 u_time; uniform lowp vec4 u_color; It's better to calculate UV coordinates in the ...


4

Khronos provides a reference GLSL compiler. It is capable of validating GLSL up to version 3.50 (full support) and up to 4.50 (partial support). It also handles ESSL (OpenGL ES's GLSL). The tool verifies that the shader conforms to the GLSL specification. This does not necessarily guarantee that it works with all drivers but it does guarantee that the ...


1

You are using GL_DEPTH_COMPONENT24 which is a fixed-point format clamped to the range [0, 1] inclusively. The floating point formats are GL_DEPTH_COMPONENT32F and DEPTH32F_STENCIL8. glTexImage2D GL_TEXTURE_2D 0 GL_DEPTH_COMPONENT32F shadowMapResolution shadowMapResolution 0 ...


1

This is probably the issue: https://www.opengl.org/wiki/Framebuffer_Object#Feedback_Loops Using a texture that is currently bound to an FBO that is current bound as the rendering target is undefined. You must unbind the FBO before using the texture. You can leave the texture bound to the FBO so long as the FBO itself is unbound. You need to bind a 2nd FBO ...


1

Check if you have mipmaps enabled on the texture samplers ( GL_LINEAR_MIPMAP_LINEAR, etc ). If the texture is incomplete (only 1 mipmap level is rendered to by the FBO at a time) and mipmaps are enabled on the sampler you'll get white textures. Switch to GL_LINEAR or GL_NEAREST set GL_TEXTURE_MAX_LEVEL​ to 0 so it only use the first mipmap (same as no ...


0

Thank you Stephane for your answer. It helped me find the real problem source. I'll explain it in this answer and will provide short answers to your post. Maybe it will be useful for someone. My AMD card is Radeon HD5770 (supporting OpenGL 4.2) and my NVidia card GeForce 9500GT (supporting OpenGL 3.3). Both cards support max 8 color attachments. try ...


0

What you need to do to draw a quad with x,y as its top left coords, r as rotation, and cx and cy as the center of rotation (relative to its x,y coord) : - translate(x,y) - rotate(r) - translate(cx, cy); - draw. - (reverse/pop the matrix if required. etc) For your case, try this: ... glTranslatef(hero.xValue(), hero.yValue(), 0); glRotatef(0, 0, 0, 1); ...


1

The transformation Matrix to transform from the space on the left to the space on the right is [1 0 0 1 ] [0 1 0 -1.5] [0 0 1 0 ] [0 0 0 1 ] Well this is not correct, the matrix you have shown is actually to transform any point from the space on the right to the space on the left. The correct matrix to transform from the ...


3

try using a multiplicative "bias" instead of additive: shadowCoordinate.z *= 0.98; If you're doing the sampling yourself rather than using the shadow comparator interpolating the shadow map helps reduce acne a lot. There shouldn't be any shadow visible behind the object as the light should not affect it with the light being completely occluded by the ...


4

There isn't much info to go on so I'm going to throw out a few things to try and see if the driver/card likes it better that way: RGBA instead of RGB glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, x, y, 0, GL_RGBA, GL_FLOAT, NULL); Check that GL_MAX_COLOR_ATTACHMENTS is 4 or more on this graphic card (GL_COLOR_ATTACHMENT2 + 1 == 4th color attachment) Try ...


1

I wrote this longish list of notes about cross platform stuff, but by the end I realized that @glampert's advice for GLFW is probably perfect. I'll post this, anyway, maybe it is useful. You can separate the concepts of “code portability” and “project portability”, though sometimes they go hand-in-hand. Plenty of cross platform development efforts will ...


2

1: camera space, like Andon said. 2: the projection matrix contains those Fx,Fy values (f and f/aspect) at cells [0][0] and [1][1] see https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml 2x/Vx-1.0 is to convert from screen pixel coordinates which are from (0, 0) to (WIDTH, HEIGHT) to 3D projected coordinates that are from -1 to 1. 3: the "real" ...


3

If you use OpenGL 3.2, it's required.


0

I got my answer: The mat4 simply applies a rotation to the vec3, and that rotation information is stored only in the 3x3 part of that mat4, so i can safely cast the mat4 to a mat3 and multiply with the vec3 to get things going, something like m_look = mat3(rotation)*m_look; That would give me what i wanted. I can then normalize my vec3.


1

I think you have two options. (1) You could go for a view-space effect where you render everything first and then apply the heat-distortion as a post-processing effect to the 2D rendered scene. (2) Alternatively you could apply the effect in world space through vertex displacements in the vertex shader stage. (1) View-space distortion could make use of the ...


1

"Which of these options is better from a practical point of view?" I'll interpret the word "practical" here to be distinct from "theoretically highest performance on a computer"... At two triangles per sprite, recomputing all the vertices on the host CPU will be not that expensive, & easy to think about. Or, since all the geometries are the same (two ...


1

You aren't limited to having only one MVP per VBO. So you would not in fact need to update the VBO every frame just because you stuff all of your sprites into a single VBO. What I do is store an instance ID with each vertex, which changes only on a per-model basis, and use those instance ID's to index into a uniform array of mat4's, one for each "instance."


1

I would suggest trying Marching Squares to generate polygons from a binary image.


0

I recall reading this: alternative method (there a few) for terrain assignment; I suggest you review and adopt this approach instead of your initial attempts. This approach differs from with your method in that the example uses an existing greyscale bitmap as the heightfield and reads the image-data to assign the elevation of the 'hills.' However, this ...


5

There are many cleaver ways of drawing 2D geometry with modern shader-centric OpenGL. The method that I usually choose and find the most straightforward is with simple batching. On startup, create a system-side buffer of 2D vertexes (the batch). This buffer can have a fixed size or can be resizable (like a std::vector in C++). Also create a VBO with the ...


2

Create a program that takes the relevant parameters as uniforms and pass those. Then the size and position of a rect can be passed as a single vec4 uniform and you only need to pass a single VBO that is 0,0; 0,1; 1,1; 1,0 (or 0,0; 0,1; 1,1; 0,0; 1,1; 1,0 for non indexed draws) in vec2 input; varrying texCoords; uniform vec4 posSize;//xy is the position zw ...


4

It would be nice if I could retrieve the values from memory after the the shader has calculated them but it doesn't seem possible - or advisable But, it IS possible, and I would advise it: https://www.opengl.org/wiki/Transform_Feedback


9

I understand that having the same "size" each attachment can be aligned better, but practically speaking is it better to waste channels (or reserve them for future use) and having all the RTs of the same size or I should use just what needed? Having a 32bit aligned Render Targets is better, even if it means "wasting" some memory. This will be much ...


2

When drawing 2D over 3D you don't need to apply view matrix. You only need to apply the orthographic projection. Applying the view matrix dones't work because it changes the position and rotation of the objects relative to the camera you don't want that.


0

You should: bind the shader with the modelview matrix for transforming the first object bind the buffer with the vertex data for the first object draw bind the shader with the modelview matrix for transforming the second object (or use the same shader and change only matrix through uniform) bind buffer with the vertex data for the second object draw ...


-1

So, it seems that the light vector wasn't in the camera space.... so, be sure to transform lights into the camera space prior to sending to the shader



Top 50 recent answers are included