Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:35+00:00 2026-05-29T09:20:35+00:00

I see a lot of different fragment shaders, #version 130 out vec4 flatColor; void

  • 0

I see a lot of different fragment shaders,

#version 130

out vec4 flatColor;

void main(void)
{
    flatColor = vec4(0.0,1.0,0.0,0.5);
}

And they all use a different variable for the "out color" (in this case flatColor). So how does OpenGL know what you’re trying to do?

I’m guessing this works because flatColor is the only variable defined as out, but you’re allowed to add more out variables aren’t you? Or would that just crash?


Actually, as a test, I just ran this:

#version 330

in vec2 TexCoord0;

uniform sampler2D TexSampler;

out vec4 x;
out vec4 y;

void main()
{
    y = texture2D(TexSampler, TexCoord0.xy);
}

It worked fine whether I used x or y.

(answer: the compiler is optimizing out the unused var, so the remaining var is assigned to location 0)


Furthermore, we have a predefined gl_FragColor. What’s the difference, and why do people usually insist on using their own variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:20:36+00:00Added an answer on May 29, 2026 at 9:20 am

    Furthermore, we have a predefined gl_FragColor.

    Let’s start with this. No, you don’t have the predefined gl_FragColor. That was removed from core OpenGL 3.1 and above. Unless you’re using compatibility (in which case, your 3.30 shaders should say #version 330 compatibility at the top), you should never use this.

    Now, back to user-defined fragment shader outputs. But first, a quick analogy.

    Remember how, in vertex shaders, you have inputs? And these inputs represent vertex attribute indices, the numbers you pass to glVertexAttribPointer and glEnableVertexAttribArray and so forth? You set up which input pulls from which attribute. In GLSL 3.30, you use this syntax:

    layout(location = 2) in color;
    

    This sets the color vertex shader input to come from attribute location 2. Before 3.30 (or without ARB_explicit_attrib_location), you would have to either set this up explicitly with glBindAttrbLocation before linking or query the program for the attribute index with glGetAttribLocation. If you don’t explicitly provide an attribute location, GLSL will assign a location arbitrarily (ie: in an implementation-defined manner).

    Setting it in the shader is almost always the better option.

    In any case, fragment shader outputs work almost exactly the same way. Fragment shaders can write to multiple output colors, which themselves get mapped to multiple buffers in the framebuffer. Therefore, you need to indicate which output goes to which fragment output color.

    This process begins with the fragment output location value. It’s set very similarly to vertex shader input locations:

    layout(location = 1) out secColor;
    

    There are also the API functions glBindFragDataLocation and glGetFragDataLocation, which are analogous to glBindAttribLocation and glGetAttribLocation.

    If you don’t do any explicit assignments, implementations usually will assign one of your output variables to location 0. However, the OpenGL standard does not require this behavior, so you should not depend on it either.

    Now to be fair, your program should have failed to link when you used two outputs that didn’t get different output locations. What probably happened was that your compiler optimized the one you didn’t write to out, so it kinda forgot about it when it came time to check for linker errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see a lot of different point of views on internet concerning meta tags
I see a lot of references to compressed JSON when it comes to different
I see a lot of different styles of variable names used in different kind
I am reviewing a site and i see a lot of different conventions on
I see there are a whole lot of different ways to check the typeof
I see a lot of people using a variety of different methods to check
I use fan gates on a lot of different fan pages. The idea has
I see lot of new machines and laptops now having 64 bit hardware and
I see a lot of JDK 1.6 notes about how to open an HTML
I see a lot of people are using code under viewDidLoad to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.