You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
problems with loading uniforms...
im trying to set a simple color but if i try to use the uniform it dosnt work if i use a simple shader with a solid color i got no problems and the color is applyed but if i try to use the uniform i get an OpenGL error 1282 for some reasons i also tryed to load the shader from a .frag file and added the plain string to the rust file and yes i use u8 to provide the data this is a thing of my data generator that compiles all files in assets to u8
here is the rust code
pub(crate) fn draw_sidebar(size: f32, alignment: Alignment) {
let topbar_vertex_shader = compile_shader_from_u8(&shaders::topbar::vertex_shader::SHADER_DATA, gl::VERTEX_SHADER); // Use the same shader as the default vertex shader
let topbar_fragment_shader = compile_shader_from_u8(&shaders::topbar::fragment_shader::SHADER_DATA, gl::FRAGMENT_SHADER); // Use the same shader as the default fragment shader
let topbar_shader_program = shaders::create_program();
shaders::attach_shader(topbar_shader_program, topbar_vertex_shader);
shaders::attach_shader(topbar_shader_program, topbar_fragment_shader);
shaders::link_program(topbar_shader_program);
unsafe {
let frag_color_location = gl::GetUniformLocation(topbar_shader_program, CString::new("vertexColor").unwrap().as_ptr());
if frag_color_location == -1 {
println!("Error: Failed to find uniform location for vertexColor");
} else {
let color: [f32; 4] = [1.0, 0.0, 0.0, 1.0]; // Red color
gl::Uniform4fv(frag_color_location, 1, color.as_ptr());
let error = gl::GetError();
if error != gl::NO_ERROR {
println!("OpenGL error: {}", error);
}
}
}
// Activate the shader program
unsafe {
shaders::use_program(topbar_shader_program);
// Vertex data for a square
let mut vertices: [f32; 8] = match alignment {
Alignment::Left =>
[
-1.0 + (size / 10.0), 1.0, // Top-left
-1.0, 1.0, // Top-right
-1.0, -1.0, // Bottom-right
-1.0 + (size / 10.0), -1.0, // Bottom-left
],
Alignment::Right =>
[
1.0-(size/10.0), 1.0, // Top-left
1.0, 1.0, // Top-right
1.0, -1.0, // Bottom-right
1.0-(size/10.0), -1.0, // Bottom-left
]
};
// Generate and bind VAO
gl::GenVertexArrays(1, &mut VAO);
gl::BindVertexArray(VAO);
// Generate VBO and bind buffer
gl::GenBuffers(1, &mut VBO);
gl::BindBuffer(gl::ARRAY_BUFFER, VBO);
// Define buffer data and attributes
gl::BufferData(gl::ARRAY_BUFFER,
(vertices.len() * std::mem::size_of::<f32>()) as GLsizeiptr,
vertices.as_ptr() as *const GLvoid,
gl::STATIC_DRAW);
// Specify vertex attributes
gl::VertexAttribPointer(0, 2, gl::FLOAT, gl::FALSE,
2 * std::mem::size_of::<f32>() as GLsizei,
ptr::null());
gl::EnableVertexAttribArray(0);
gl::DrawArrays(gl::TRIANGLE_FAN, 0, 4);
}
}
problems with loading uniforms...
im trying to set a simple color but if i try to use the uniform it dosnt work if i use a simple shader with a solid color i got no problems and the color is applyed but if i try to use the uniform i get an OpenGL error 1282 for some reasons i also tryed to load the shader from a .frag file and added the plain string to the rust file and yes i use u8 to provide the data this is a thing of my data generator that compiles all files in assets to u8
here is the rust code
and here the shader code
The text was updated successfully, but these errors were encountered: