glCreateProgram().uniform in python












1















I am trying to port some javascript code with opengl to python. But cannot figure out what I am doing wrong in translating prog.uniform[u] = gl.getUniformLocation(prog, u);



Javascript:



let v = buildShader(vert, gl.VERTEX_SHADER);
let f = buildShader(frag, gl.FRAGMENT_SHADER);
let prog = gl.createProgram();
gl.attachShader(prog, v);
gl.attachShader(prog, f);
gl.linkProgram(prog);
prog.uniform = {};
u = ['model','bounds','frac','aspect'];
_.each(u, function(u){ prog.uniform[u] = gl.getUniformLocation(prog, u); });


Python3/PyOpenGl:



v = self.buildShader(vert, GL_VERTEX_SHADER)
f = self.buildShader(frag, GL_FRAGMENT_SHADER)
prog = glCreateProgram()
glAttachShader(prog, v)
glAttachShader(prog, f)
glLinkProgram(prog)
for u in ['model','bounds','frac','aspect']:
loc = glGetUniformLocations(prog,u)
glProgramUniform(prog,loc,u)









share|improve this question



























    1















    I am trying to port some javascript code with opengl to python. But cannot figure out what I am doing wrong in translating prog.uniform[u] = gl.getUniformLocation(prog, u);



    Javascript:



    let v = buildShader(vert, gl.VERTEX_SHADER);
    let f = buildShader(frag, gl.FRAGMENT_SHADER);
    let prog = gl.createProgram();
    gl.attachShader(prog, v);
    gl.attachShader(prog, f);
    gl.linkProgram(prog);
    prog.uniform = {};
    u = ['model','bounds','frac','aspect'];
    _.each(u, function(u){ prog.uniform[u] = gl.getUniformLocation(prog, u); });


    Python3/PyOpenGl:



    v = self.buildShader(vert, GL_VERTEX_SHADER)
    f = self.buildShader(frag, GL_FRAGMENT_SHADER)
    prog = glCreateProgram()
    glAttachShader(prog, v)
    glAttachShader(prog, f)
    glLinkProgram(prog)
    for u in ['model','bounds','frac','aspect']:
    loc = glGetUniformLocations(prog,u)
    glProgramUniform(prog,loc,u)









    share|improve this question

























      1












      1








      1








      I am trying to port some javascript code with opengl to python. But cannot figure out what I am doing wrong in translating prog.uniform[u] = gl.getUniformLocation(prog, u);



      Javascript:



      let v = buildShader(vert, gl.VERTEX_SHADER);
      let f = buildShader(frag, gl.FRAGMENT_SHADER);
      let prog = gl.createProgram();
      gl.attachShader(prog, v);
      gl.attachShader(prog, f);
      gl.linkProgram(prog);
      prog.uniform = {};
      u = ['model','bounds','frac','aspect'];
      _.each(u, function(u){ prog.uniform[u] = gl.getUniformLocation(prog, u); });


      Python3/PyOpenGl:



      v = self.buildShader(vert, GL_VERTEX_SHADER)
      f = self.buildShader(frag, GL_FRAGMENT_SHADER)
      prog = glCreateProgram()
      glAttachShader(prog, v)
      glAttachShader(prog, f)
      glLinkProgram(prog)
      for u in ['model','bounds','frac','aspect']:
      loc = glGetUniformLocations(prog,u)
      glProgramUniform(prog,loc,u)









      share|improve this question














      I am trying to port some javascript code with opengl to python. But cannot figure out what I am doing wrong in translating prog.uniform[u] = gl.getUniformLocation(prog, u);



      Javascript:



      let v = buildShader(vert, gl.VERTEX_SHADER);
      let f = buildShader(frag, gl.FRAGMENT_SHADER);
      let prog = gl.createProgram();
      gl.attachShader(prog, v);
      gl.attachShader(prog, f);
      gl.linkProgram(prog);
      prog.uniform = {};
      u = ['model','bounds','frac','aspect'];
      _.each(u, function(u){ prog.uniform[u] = gl.getUniformLocation(prog, u); });


      Python3/PyOpenGl:



      v = self.buildShader(vert, GL_VERTEX_SHADER)
      f = self.buildShader(frag, GL_FRAGMENT_SHADER)
      prog = glCreateProgram()
      glAttachShader(prog, v)
      glAttachShader(prog, f)
      glLinkProgram(prog)
      for u in ['model','bounds','frac','aspect']:
      loc = glGetUniformLocations(prog,u)
      glProgramUniform(prog,loc,u)






      python opengl shader pyopengl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 16:46









      NardNard

      647




      647
























          1 Answer
          1






          active

          oldest

          votes


















          3














          glProgramUniform assigns a value to a uniform, where the 3rd paramter is the value.



          glProgramUniform(prog,loc,u) makes not any sense, when u is string which is the name name of the uniform.



          You have to create a dictionary which contains the locations of a uniform for each name:



          uniform = {}
          for u in ['model','bounds','frac','aspect']:
          uniform[u] = glGetUniformLocation(prog, u)


          or simply



          uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }





          share|improve this answer


























          • Thx, how to port the prog.uniform[u]= part to python3?

            – Nard
            Nov 24 '18 at 17:55








          • 1





            @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

            – Rabbid76
            Nov 24 '18 at 17:58











          • Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

            – Nard
            Nov 24 '18 at 18:05








          • 1





            @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

            – Rabbid76
            Nov 24 '18 at 18:32











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460303%2fglcreateprogram-uniform-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          glProgramUniform assigns a value to a uniform, where the 3rd paramter is the value.



          glProgramUniform(prog,loc,u) makes not any sense, when u is string which is the name name of the uniform.



          You have to create a dictionary which contains the locations of a uniform for each name:



          uniform = {}
          for u in ['model','bounds','frac','aspect']:
          uniform[u] = glGetUniformLocation(prog, u)


          or simply



          uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }





          share|improve this answer


























          • Thx, how to port the prog.uniform[u]= part to python3?

            – Nard
            Nov 24 '18 at 17:55








          • 1





            @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

            – Rabbid76
            Nov 24 '18 at 17:58











          • Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

            – Nard
            Nov 24 '18 at 18:05








          • 1





            @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

            – Rabbid76
            Nov 24 '18 at 18:32
















          3














          glProgramUniform assigns a value to a uniform, where the 3rd paramter is the value.



          glProgramUniform(prog,loc,u) makes not any sense, when u is string which is the name name of the uniform.



          You have to create a dictionary which contains the locations of a uniform for each name:



          uniform = {}
          for u in ['model','bounds','frac','aspect']:
          uniform[u] = glGetUniformLocation(prog, u)


          or simply



          uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }





          share|improve this answer


























          • Thx, how to port the prog.uniform[u]= part to python3?

            – Nard
            Nov 24 '18 at 17:55








          • 1





            @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

            – Rabbid76
            Nov 24 '18 at 17:58











          • Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

            – Nard
            Nov 24 '18 at 18:05








          • 1





            @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

            – Rabbid76
            Nov 24 '18 at 18:32














          3












          3








          3







          glProgramUniform assigns a value to a uniform, where the 3rd paramter is the value.



          glProgramUniform(prog,loc,u) makes not any sense, when u is string which is the name name of the uniform.



          You have to create a dictionary which contains the locations of a uniform for each name:



          uniform = {}
          for u in ['model','bounds','frac','aspect']:
          uniform[u] = glGetUniformLocation(prog, u)


          or simply



          uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }





          share|improve this answer















          glProgramUniform assigns a value to a uniform, where the 3rd paramter is the value.



          glProgramUniform(prog,loc,u) makes not any sense, when u is string which is the name name of the uniform.



          You have to create a dictionary which contains the locations of a uniform for each name:



          uniform = {}
          for u in ['model','bounds','frac','aspect']:
          uniform[u] = glGetUniformLocation(prog, u)


          or simply



          uniform = { u : glGetUniformLocation(prog, u) for u in ['model','bounds','frac','aspect'] }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 17:31

























          answered Nov 24 '18 at 16:58









          Rabbid76Rabbid76

          38.2k123249




          38.2k123249













          • Thx, how to port the prog.uniform[u]= part to python3?

            – Nard
            Nov 24 '18 at 17:55








          • 1





            @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

            – Rabbid76
            Nov 24 '18 at 17:58











          • Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

            – Nard
            Nov 24 '18 at 18:05








          • 1





            @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

            – Rabbid76
            Nov 24 '18 at 18:32



















          • Thx, how to port the prog.uniform[u]= part to python3?

            – Nard
            Nov 24 '18 at 17:55








          • 1





            @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

            – Rabbid76
            Nov 24 '18 at 17:58











          • Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

            – Nard
            Nov 24 '18 at 18:05








          • 1





            @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

            – Rabbid76
            Nov 24 '18 at 18:32

















          Thx, how to port the prog.uniform[u]= part to python3?

          – Nard
          Nov 24 '18 at 17:55







          Thx, how to port the prog.uniform[u]= part to python3?

          – Nard
          Nov 24 '18 at 17:55






          1




          1





          @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

          – Rabbid76
          Nov 24 '18 at 17:58





          @Nard No way, because in python prog is t name of the shader program object, which is just a number. You have to create a tuple (prog, uniform).

          – Rabbid76
          Nov 24 '18 at 17:58













          Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

          – Nard
          Nov 24 '18 at 18:05







          Stupid question probably, but then how do I pass the uniform-variable to opengl or is this not what is happening in the js-code prog.uniform[u] = ?

          – Nard
          Nov 24 '18 at 18:05






          1




          1





          @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

          – Rabbid76
          Nov 24 '18 at 18:32





          @Nard No prog.uniform[u] doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done by gl.Uniform*

          – Rabbid76
          Nov 24 '18 at 18:32




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460303%2fglcreateprogram-uniform-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'