+ 1
debug code
I want to change the color of the graph and lines. I tried a lot of scenarios but the problem wasn't solved. uniform variable does not work in both codes(vertex code, and fragment code). i can't find the bug!my code is readable nearly. https://code.sololearn.com/WuO71irfT3OG/?ref=app
4 Respostas
+ 2
Hi Mehran,
This should get the red and yellow lines that you want. Notice that I moved your color and color2 code into your draw function. You can't set uniform values until useProgram is called with the program that uses that uniform. This was your mistake. I commented the changes below to highlight what I did.
var dx=gl.getUniformLocation(shaderProgram,"dx");
var color2=gl.getUniformLocation(shaderProgram2, "color") ;
var color=gl.getUniformLocation(shaderProgram, "color") ;
// JOSH SAYS DON'T CALL gl.uniform... functions here because useProgram didn't run yet.
function draw(){
if(stateChanged){
//drawing lines
gl.useProgram(shaderProgram2);
gl.uniform4fv(color2,[1.0,0.0,0.0,1.0]); // THIS WAS MOVED BY JOSH
gl.drawArrays(gl.LINES,0,4);
gl.useProgram(shaderProgram)
//setting colors; Note:bug is here
gl.uniform4fv(color,[1.0,1.0,0.0,1.0]); // THIS WAS MOVED BY JOSH
var i= +range.value;
If you checked the JavaScript console in your web browser while running your code, you'd see a message about this. I saw this message in the JavaScript console from Edge when running your unfixed version: "WebGL: INVALID_OPERATION: uniform4fv: location is not from current program"
If you have a laptop, try to debug your code there. It is a lot easier to see line numbers for errors and other troubleshooting data if you debug a web page directly in a web browser instead of getting it manipulated by Sololearn's Code Playground feature and having it run within Sololearn's iframe.
+ 1
Josh Greig can you help me?
i know you are familiar with GLSL
+ 1
Oh i find it.
we should set uniforms after declaration using shader program.
+ 1
Josh Greig .
thanks for your answer.
i forget checking it in laptop.
because i thought this does not show any warn/error.