GLSL troubles -- whole screen is black

My code is kind of a Rube Goldberg machine–I’m trying to execute a shader, using sdl_gpu, which is built on SDL, and I’m trying to do it in Ada.

But I think my problem is more fundamental than that. So fundamental that nobody asks it, so I can’t find the answer. My question is how do I apply a shader?

Tutorials always talk about installing the shader, which I can definitely do. I know this because if I do it wrong, it doesn’t show black, but instead shows the image I want to eventually process. So if it turns black, I’m at least telling the GPU not to do the normal thing.

My question is more like, I’ve installed the shader (I think) but what do I do now? Do I have to pass it a quadrilateral to draw on? Does installing it make it automatically adjust anything I draw? When should I activate it? When should I deactivate it? How do I know it’s done before I deactivate it?

I’ve been at it for months. Read the Orange Book. Read the whole sdl_gpu documentation. Countless tutorials. Invariably, my shader compiles fine but just shows black. Black black black.

According to the Orange Book, if I don’t specify a vertex shader, it will just default to the default Vertex stuff, which… I guess is a good thing? I didn’t have anything I wanted or needed to do at the vertex level. I’m trying to (eventually) adjust a flat image. You know, Gaussian Blur, Rain, that kind of thing. But before I do anything that complicated, I just want the screen to turn orange. Why orange? Well, it’s my favorite color, but more importantly, it’s not black, so if the screen turns orange, I’ll know it works.

Here’s my fragment shader code:

#version 130

void main()
    gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0);

Sources disagree about whether I’m supposed to declare my own out variable to set the color to, or use this gl_FragColor. I’ve tried it both ways and both ways it’s all black. I’ve also tried it with a generic passthrough vertex shader, and with or without, it’s also always black.

The one thing I suspect is that I can find nothing in the sdl_gpu documentation to bind the output (analogous to glBindFragData). So not being able to do that may (or may not) be an issue.

I can post my application code, if anybody feels up to the challenge of debugging something so far abstracted. But like I mentioned, I have a feeling it’s something I misunderstand about the process.

Thanks! I hope I don’t sound as frustrated as I feel, haha.

I think that you’re going to need to ask on a forum which deals specifically with SDL_gpu.

There’s nothing wrong with the fragment shader, and there really aren’t many plausible mistakes which would result in the program neither using the fragment shader (rendering in orange) nor continuing as before. So it seems like some requirement of SDL_gpu isn’t being met.

Personally, I’d suggest simply not using SDL_gpu. SDL is a perfectly reasonable solution for creating windows, creating contexts for windows, and handling input. The add-ons which go beyond that and try to turn it into a higher-level graphics toolkit could reasonably be described as a solution in search of a problem to solve.

Just create the window and context then just use the OpenGL API for everything related to OpenGL.

Hi, thanks for taking the time to answer.

However, I’m afraid I’m still no closer to understanding how to use a shader once it’s installed. Or do you mean to say that I should be expecting the whole screen to turn orange simply by virtue of having compiled, linked, etc without explicitly handling output, or interacting with it before/after normal drawing each frame, etc? Suppose I were using OpenGL directly.

Using the shader program you posted (with glUseProgram) should result in any geometry being rendered in orange. As the program doesn’t have any inputs, nothing else should be required.

1 Like