glCreateProgram().uniform in python
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
add a comment |
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
add a comment |
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
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
python opengl shader pyopengl
asked Nov 24 '18 at 16:46
NardNard
647
647
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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'] }
Thx, how to port theprog.uniform[u]=
part to python3?
– Nard
Nov 24 '18 at 17:55
1
@Nard No way, because in pythonprog
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 theuniform
-variable to opengl or is this not what is happening in the js-codeprog.uniform[u] =
?
– Nard
Nov 24 '18 at 18:05
1
@Nard Noprog.uniform[u]
doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done bygl.Uniform
*
– Rabbid76
Nov 24 '18 at 18:32
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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'] }
Thx, how to port theprog.uniform[u]=
part to python3?
– Nard
Nov 24 '18 at 17:55
1
@Nard No way, because in pythonprog
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 theuniform
-variable to opengl or is this not what is happening in the js-codeprog.uniform[u] =
?
– Nard
Nov 24 '18 at 18:05
1
@Nard Noprog.uniform[u]
doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done bygl.Uniform
*
– Rabbid76
Nov 24 '18 at 18:32
add a comment |
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'] }
Thx, how to port theprog.uniform[u]=
part to python3?
– Nard
Nov 24 '18 at 17:55
1
@Nard No way, because in pythonprog
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 theuniform
-variable to opengl or is this not what is happening in the js-codeprog.uniform[u] =
?
– Nard
Nov 24 '18 at 18:05
1
@Nard Noprog.uniform[u]
doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done bygl.Uniform
*
– Rabbid76
Nov 24 '18 at 18:32
add a comment |
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'] }
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'] }
edited Nov 24 '18 at 17:31
answered Nov 24 '18 at 16:58
Rabbid76Rabbid76
38.2k123249
38.2k123249
Thx, how to port theprog.uniform[u]=
part to python3?
– Nard
Nov 24 '18 at 17:55
1
@Nard No way, because in pythonprog
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 theuniform
-variable to opengl or is this not what is happening in the js-codeprog.uniform[u] =
?
– Nard
Nov 24 '18 at 18:05
1
@Nard Noprog.uniform[u]
doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done bygl.Uniform
*
– Rabbid76
Nov 24 '18 at 18:32
add a comment |
Thx, how to port theprog.uniform[u]=
part to python3?
– Nard
Nov 24 '18 at 17:55
1
@Nard No way, because in pythonprog
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 theuniform
-variable to opengl or is this not what is happening in the js-codeprog.uniform[u] =
?
– Nard
Nov 24 '18 at 18:05
1
@Nard Noprog.uniform[u]
doesn't assign anything to uniform variable on the GPU in WebGL (not OpenGL). This is done bygl.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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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