Tag Info

Hot answers tagged

6

You are using pointers to data inside a temporary object: const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); Which means both vertex_shader and fragment_shader are pointing to invalid memory, since the strings returned by load_shader get destroyed at the end of each statement. ...


4

You don't set these values in the shader. You set them in your program, generally when first creating the texture (though it can be set or changed whenever). If you've already uploaded your texture data to OpenGL then all you have to do is this: First bind the texture if it is not already. glBindTexture(GL_TEXTURE_2D, texture_id); Then set the ...


2

The other answers already mention that you're getting a dangling pointer and should return the strings. But reading shaders from a file, really comes down to putting the whole file into a string. Here's one way to do it: // Read shader file into one string std::string shaderSource; if ( !readFileIntoString( shaderFileName, shaderSource ) ) { return ...


2

That structure is not aligned correctly, which may be the source of your problem. To form an array using std140 out of PLight, you need to pad it with an extra float at the end. Otherwise, PLight pLights[TOTAL_LIGHTS] is misaligned and you will fetch the wrong memory from pLights [1] -- everything will be off by 1 scalar component on the second light in ...


1

Finally got it working!!! The problem indeed was in the fragment shader. First of all, there was no need to invert the position, the error came from the UV coordinates. Finally I remembered when I was using XNA the textures where flipped vertically respect to OpenGL, and that was the problem. After flipping the V coordinate and correcting the reversed ...


1

Figured it out by looking other shader examples and hopefully it will benefit others. elapsedTime can be added to the computation or offset and will animate the effect, some use sin/cos as well.. uniform float elapsedTime;


1

I found that replacing v_texcoord0 with gl_FragCoord.xy / vec2(screen_width, screen_height) in the SSAO shader, solved this issue.


1

One way of doing this is creating and loading an image into memory that is as large as the background. However, this seems like a horrible waste of memory. To affect the whole screen with a fragment shader you don't need a full-screen texture, just a full-screen polygon (one quad or two triangles). The four vertices would have attributes on them. At the ...


1

If you are just filling with a solid color then you could pass that color to the fragment shader as a uniform, and process it from there. Use a full screen quad for the fragment shader to render onto. Another way is to this to render the background to an FBO and do the full screen quad trick but apply the FBO texture to it. This would be very memory ...


1

Modern hardware performs early stencil testing using the same sort of tile-based approach as early depth. It can reject large groups of fragments before they make it to the fragment shader stage. That means shader units will not waste time calculating data they are just going to throw out anyway. You add an extra 8-bits of memory per-pixel (pretty much a ...


1

const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); will result in dangling pointers (with undefined behavior if you dereference it), after you assign the char* to the variable the temp std::string (and backing array you just got a pointer to) gets deleted. const std::string ...


1

What a dump question. I put the cubemap to the wrong samplerCube. I assigned the map to cubemap[1] not cubemap[0]. Great example of "I wouldn't do something like this. The error must be somewhere in the OpenGL code!" :D


1

The way to do this is with a FBO (Frame Buffer Object). You can render each pass to a FBO and use it as a texture input in the next stage, any kind of deferred shading and post processing is reliant upon this functionality. https://www.opengl.org/wiki/Framebuffer_Object


1

sRGB in graphics APIs is defined by the x^2.2 gamma curve. pow(x, 2.2) and pow(x, 1.0/2.2) for sRGB-to-linear and linear-to-sRGB, respectively. Where did you get the idea that anything more complex than that is necessary? As for a "simple" version: just use x*x and sqrt(x). Few people would notice, and not without taking a screenshot and analyzing it.



Only top voted, non community-wiki answers of a minimum length are eligible