Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. passing variables to GLSL

passing variables to GLSL

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsgame-devtutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James_722
    wrote on last edited by
    #1

    I have been working with GLSL for a couple days and I understand the basic concept. I know how to get specific values from my openGL applicaiton to the shader but I don't know how to pass in my own variables. I appreciate your help with this problem.

    C 1 Reply Last reply
    0
    • J James_722

      I have been working with GLSL for a couple days and I understand the basic concept. I know how to get specific values from my openGL applicaiton to the shader but I don't know how to pass in my own variables. I appreciate your help with this problem.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Could you be more specific, please? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      J 1 Reply Last reply
      0
      • C CPallini

        Could you be more specific, please? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        J Offline
        J Offline
        James_722
        wrote on last edited by
        #3

        I know that values such as light position can be passed into either the fragment shader or the vertex shader using gl_lightsource, but what if I wanted to use a variable from my code such as an eye vector for a phong equation. In the information on GLSL I have read I have not seen a mention as to how to do something like this. All I have seen is being able to pass data in that would normally be used in OpenGL's lighting model, such as the functions glMaterialfv and glLightfv. I hope this better explains my problem.

        C 1 Reply Last reply
        0
        • J James_722

          I know that values such as light position can be passed into either the fragment shader or the vertex shader using gl_lightsource, but what if I wanted to use a variable from my code such as an eye vector for a phong equation. In the information on GLSL I have read I have not seen a mention as to how to do something like this. All I have seen is being able to pass data in that would normally be used in OpenGL's lighting model, such as the functions glMaterialfv and glLightfv. I hope this better explains my problem.

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          Been a couple years but IIRC ... If you have a vertex shader with: attribute float myAttrib; Then in the C++ source you would: GLint loc = glGetAttribLocation(progId, "myAttrib"); or, GLint loc = 20; glBindAttribLocation(progId, loc, "myAttrib"); then to set myAttrib, glVertexAttrib1f(loc, 0.432); So you can set per-vertex in C++ and read (only) in shader. ... uniforms are similar. If you want to bind then do so after glAttachShader and before glLinkProgram. I think OpenGL 3+ changes the above slightly, haven't gotten up to speed on it yet.

          ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

          J 1 Reply Last reply
          0
          • C cmk

            Been a couple years but IIRC ... If you have a vertex shader with: attribute float myAttrib; Then in the C++ source you would: GLint loc = glGetAttribLocation(progId, "myAttrib"); or, GLint loc = 20; glBindAttribLocation(progId, loc, "myAttrib"); then to set myAttrib, glVertexAttrib1f(loc, 0.432); So you can set per-vertex in C++ and read (only) in shader. ... uniforms are similar. If you want to bind then do so after glAttachShader and before glLinkProgram. I think OpenGL 3+ changes the above slightly, haven't gotten up to speed on it yet.

            ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

            J Offline
            J Offline
            James_722
            wrote on last edited by
            #5

            Thank you, this has been very helpful, I just have one more question; what about vec3, vec4, etc. This might be a stupid question, there might be a data structure in opengl that can handle data from these types, but what do i do about these data types?

            C 1 Reply Last reply
            0
            • J James_722

              Thank you, this has been very helpful, I just have one more question; what about vec3, vec4, etc. This might be a stupid question, there might be a data structure in opengl that can handle data from these types, but what do i do about these data types?

              C Offline
              C Offline
              cmk
              wrote on last edited by
              #6

              glBindAttrib*() has versions that accept all types of values. See examples at: http://www.lighthouse3d.com/opengl/glsl/index.php?ogluniform[^]

              ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

              modified on Wednesday, April 21, 2010 2:29 PM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups