Tag Info

New answers tagged

0

You should consider shader programs as similar part of the state as textures. Changing the state is expensive, so you may be able to get away with combining several textures to one to avoid texture changes; the same applies to shaders - you may be able to combine several shaders to avoid state changes. Similarly to combining textures, combining shaders ...


0

Can a tessellated square/plane be wrapped around to form a pipe (and would this approach loose accuracy)? (I've only ever manipulated vertices in the y-direction on a flat plane). It would be easiest to model a segment of a pipe as a cylinder and making an abstraction in your code so that you can think of the surface of the cylinder as a flat plane ...


1

Yes, indeed, some ES implementations don't support non-const indexing of arrays, which complicates code quite a bit. 1D textures are also not supported on GL ES 2.0 or lower. You can certainly overcome this by using a 2D texture with a height of 1 pixel. It will effectively behave like a 1D array. Another approach might also be computing the value ...


-1

i think they just blast on in parallel, so you should be right as far as I know.


1

One way to accomplish this would be to use an FBO (Frame Buffer Object) and multiple depth buffers and/or depth textures. A basic use case is shown on the Wiki at OpenGL.org. Another possible method, maybe applicable to old or very low end hardware could be copying the depth buffer, which you can find an example of using PBOs (Pixel Buffer Objects) here.


2

From your original equation a_position.x = a_position.x + amplitude * sin(phase + a_position.x); We'll just be taking at look at the sin portion as this is where this effect comes from sin(phase + a_position.x); Let's look at the sin function over a half of a period for different positions (phase is in degrees) Position 1 - a_position.x = 0 sin(0 + 0) ...


0

Okay. Seems like you just want a single light-camera. But there are many different approaches. Like using multiple frustum splits (which means multiple light-cameras), which is called "Cascaded Shadow Mapping". Even the way you construct the frustum of your light-camera to encompass the main camera's frustum can be done in various ways. First some useful ...


5

To get better results you will need to check for MSAA (http://www.opengl.org/wiki/Multisampling) Define how many samples you want for Anti-Aliasing in WGL_SAMPLES_ARB attribute passed to the function wglChoosePixelFormatARB (for Windows). You can find code for that here : http://nehe.gamedev.net/tutorial/fullscreen_antialiasing/16008/ This paper is also ...


1

There are many ways to handle this kind of logic in a shader: Use dynamic branching: Plain ifs are not that slow on modern hardware. Test and profile it. If it doesn't slow down your application, this is probably the most straightforward and flexible solution. Use shader subroutines: This is a new GLSL feature. It is supposed to be faster than dynamic ...


0

Probably the best way to go with a modern DX11 level HW today is to: Do frustum culling using octree or similar on CPU Batch objects in a frustum per frame (i.e. build dynamic instance streams for each object type in the frustum) Perform occlusion culling purely on GPU (i.e. convert the FOV instance streams to renderable instance streams). For the the ...


0

You can do this easily with quaterions: vec3 sv=normalize(sampleDirections[x]); vec3 hv=normalize(sv+vec3(0, 1, 0)); vec4 q=vec4(cross(sv, hv), dot(sv, hv)); vec3 rot_n=2*(cross(q.xyz, cross(q.xyz, n) + q.w*n) + n; Instead of storing sampleDirections, you should store the quaternion/matrix rotations of the vector to optimize computations in a shader.


0

So after a number of threads that didn't go anywhere, I finally got the answer. grimmeld, you were close. I had it fixed at 45 degrees which was my mistake (needed to adjust it according to the screen ratio). Here's the solution and conversation that led to it.


0

I have achieved this by following this algorithm, Calculate the screen point of the 3D point under the mouse cursor (the point that needs to be on fixed location) before move the camera. (Say screen point as Pt2DScr and 3D point under mouse Pt3D1) Move camera along camera Z axis. That's mean zoom to center of the viewport. Calculate current 3D point which ...


1

You can use the inbuilt GLSL lessThan() and greaterThan() functions (supported in all GLSL versions). These give two boolean vectors as a result. https://www.opengl.org/sdk/docs/man/html/greaterThan.xhtml http://www.opengl.org/sdk/docs/man4/html/lessThan.xhtml Then, you can use 'equal' (https://www.opengl.org/sdk/docs/man/html/equal.xhtml) on those ...


0

I mostly work on GLES where we don't have geometry shaders, so don't expect my code to work as-is. The problem is that you're creating the vertices in world space (3D), and then projecting them independently. If you want your text to be facing the camera regardless of the camera settings, then you want to create your vertices in screen space (2D), not ...


1

How about: vec3 delta = abs(textureColor - vec3(0.85, 0.85, 0.85)); // Get delta from middle vec3 if (delta.r <= 0.05) && (delta.g <= 0.05) && (delta.b <= 0.05) Performance needs to be profiled, but it's sure shorter to write


1

Unless you just made a large number of typos posting this code, your indexing is sloppy; some of the array elements aren't initialized, some are overwritten and at one point you index out of bounds of the array. That looks like your problem. m[0][0] = 2 / (right - left); m[0][1] = 0; m[0][2] = 0; ...


2

In SDL2 the creation of the window is separate from the rendering environment used to draw into that window. So, while you might pass "SDL_WINDOW_OPENGL" to SDL_CreateWindow(), this simply states that the window should support rendering from an OpenGL context later down the line and doesn't actually create an OpenGL context at that point. So, from ...


1

Yes, accessing memory can always be substantially slower than not accessing memory. Particularly in a for loop that's executing 2000 times inside a shader. I don't think there's anything particularly surprising, here -- breaking the task up into smaller steps that can each be executed in parallel and using smaller amounts of data should definitely help.


4

glDrawElements() doesn't support a "blank indices table". glDrawElements() must always be given explicit data about in what order vertex indices are to be drawn, either using a pointer to a memory buffer (OpenGL <= 2.1 only), or an offset into a bound VBO. glDrawArrays() acts like glDrawElements() would if it had been given an array of values [0, 1, 2, ...


1

Assuming you are dealing with additive operations (i.e. rotation translation order is important). Generally you would want to update your Camera matrix in this order: Take identity matrix. Translate to FocalPoint Rotate to look in to the right direction Translate away from the FocalPoint by the DistanceFromFocal Same works with any Object that you want ...


0

This is a general explanation answer, you'll have to check with the code yourself. Perspective projection looks like this from above: Near clipping plane is what you see on your screen. Now see that the farther you get from it, the more you need to move the object to have it in the same position on the screen. For example take Blue point, it got moved ...


1

You're not setting the projection matrix correctly. At the time you call glOrtho() you probably want to have the GL_PROJECTION matrix mode enabled. Something like that // set projection matrix GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, 1920, 1080, 0, 1, -1); // set modelview matrix to identity ...


2

Once upon a time there was Google. Now this seems to be what you are looking for: const char* SDL_GetCurrentVideoDriver(void) Returns the name of the current video driver or NULL if no driver has been initialized.


3

The way you are computing vertex normals only considers an individual quad and not its neighbours. Thus you get the discontinuities between the somewhat flat quads. If you want smooth normals, the way to compute them is to consider the gradient of nearby vertices on your grid. If you've got points on the form a-b-c | | | d-e-f | | | g-h-i then you want ...


0

Smooth shading can be enabled with glShadeModel(GL_SMOOTH) which is, however, the default. Your screenshot does look like you have the flat shading set.


0

In fact, the original question is 1 cast away from the solution. Original Code glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, window.width/window.height, 0.01f, 100.0f) Fixed Code glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, (float)window.width/window.height, 0.01f, 100.0f) The problem was that window.width and ...


-4

A spinning animation can be done in several ways. An easy way is to create 2D sprites at the bottom of the machine and move them upwards until they hit the top then you move the sprite of the machine over the sprite of the symbol. If the symbol's bottom hit the bottom of that part of the machine then you make it disappear. An alternative if you want 3D is to ...


0

I'm don't have any sources confirming it, but as far as I've tested till now, that approach provides better performance compared to using a texture of that size. I suspect the reason for getting better performance is the fact that with smaller texture there is less memory loopups gpu needs in order to render the texture, while it's still doing all the ...


4

"My goal was to teach them the fundamentals of C++ using OOP", following this, I think you're making the right choice. I find the OpenGL API doesn't lend itself to OOP( in the programming sense, anyway ) very well. I'm surprised you're even exposing 12th grades to C++ and OpenGL. Most university courses I've seen avoid both of these like the plague. So, ...


4

This is a pretty advanced topic. Generally people like to use Boolean Set Operations implemented with a BSP tree for this kind of destruction, which revolves around splitting polygons over planes. Take a look at this paper by Naylor to learn how. This will let you overlay one mesh upon another and perform a subtraction. The results of the subtraction can ...


0

The term you're looking for is Frustum Culling. The problem is this doesn't work too well on individual vertices, because a vertex may be required for a face that is inside the frustum even if the vertex itself isn't. It would be too slow to do that every frame anyway. If neither the mesh or cameras move, or they move predictably so you can precalculate ...


0

An easy way would be to first render the object and then render the water using multiplicative rendering (i.e. modulate the frame buffer color with water color). Not quite sure if it gives you the result you want though (you could test it in Photoshop for example). If you want more control you would have to first render the object, copy the result to a ...


2

I would implement it as a multipass algorithm, a bit similar to shadow maps. You render the character to a frame buffer, color(RGBA) and depth(Z). Now you simply apply the frame buffer to the regular buffer (with depth). Then you render the watter, you sample from the frame buffer. If the value A=0, you render the watter normally. If A!=0 and Z>=current ...


0

I'm using the freetype library (http://www.freetype.org/) to load glyphs from freetype fonts and then use bin packing to generate a glyph texture/atlas during runtime, similar to how freetype-gl does it (https://code.google.com/p/freetype-gl/). When the game is initialized, I generate a glyph atlas with the printable characters from the ASCII range. This ...


1

You could do this: Create a texture holding all the colors you want. For the actual button geometry, set the texture coordinates to the appropriate region of the color texture (they can all be the same value, in fact).


0

It's not clear from your image if that is a single plane and the far faces are overlaying the near ones, or if you are rendering several objects and the far ones overlay the near ones. If it's the second case, your problem is that you need to either sort the itens back to front or disable the depth test. If you render them out of order, OpenGL will discard ...


1

The shader was fine. But when I tried to use other shaders I realized what was wrong. It was the C++ code that was lacking lines (rrr!! This is the reason why I hate shaders! It's so complicated to make a link in your head between every line you write in one file and what must be written in the other for it to be recognized!). In the display function, I ...


2

Your code looks like it wants to output 9 triangles each consisting of a discreet three vertex triangle strip, not 27 triangles. However you have set max_vertices to 3 in the layout statement at the top of the shader so it only emits one triangle before it hits that limit. (The limit is for the whole shader, not per-primitive, otherwise 3 would have been ...


4

In the games I've worked on, we restricted the subset of characters used for Chinese, Japanese, and Korean (together referred to as CJK) to only those required to display the text in the game. In other words, we didn't attempt to cram in every possible character; we just took the database of CJK text from our localization teams, did a pass over it to find ...


2

This is usually solved by changing glfwSetInputMode with GLFW_CURSOR from GLFW_CURSOR_HIDDEN to GLFW_CURSOR_DISABLED. The behavior differences are due to the differences in OS APIs that GLFW uses and how they interact with the windowing system. In the documentation, it says that DISABLED should be used for 3D camera controls, and HIDDEN should be used when ...


1

It is very possible that you may be able to restructure your algorithm to work as a set of shaders, but I recall hearing a talk on the Mantle API a while ago and thought maybe that's something you could look into as an alternative to the graphics APIs mentioned (OpenGL/DirectX)... I think it lets you program graphics hardware at a lower level thus allowing ...



Top 50 recent answers are included