Closed nyendwa closed 2 years ago
Hi there, thanks for trying out this library! Typically you will bind each matrix one at a time to your shader - this allows you to independently update the model, view and projection matrices. For example, here's a typical vertex shader with those 3 matrices:
#version 130
in vec3 vertexPosition;
in vec3 vertexColor;
out vec3 color;
uniform mat4 projection_matrix;
uniform mat4 view_matrix;
uniform mat4 model_matrix;
void main(void)
{
color = vertexColor;
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(vertexPosition, 1);
}
And then for the projection and view matrices I only set them the single time, since they don't update per frame (unless the camera is moving):
program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));
Lastly, the model matrix can be updated per frame if you are animating it:
program["model_matrix"].SetValue(Matrix4.CreateRotationY(angle) * Matrix4.CreateTranslation(new Vector3(-1.5f, 0, 0)));
Hopefully this helps!
Does this function program["projection_matrix"] Require initialisation? Something like a method or class?
On Tue, Jul 19, 2022, 03:12 Charles Ambrye @.***> wrote:
Hi there, thanks for trying out this library! Typically you will bind each matrix one at a time to your shader - this allows you to independently update the model, view and projection matrices. For example, here's a typical vertex shader with those 3 matrices:
in vec3 vertexPosition; in vec3 vertexColor;
out vec3 color;
uniform mat4 projection_matrix; uniform mat4 view_matrix; uniform mat4 model_matrix;
void main(void) { color = vertexColor; gl_Position = projection_matrix view_matrix model_matrix * vec4(vertexPosition, 1); }```
And then for the projection and view matrices I only set them the single time, since they don't update per frame (unless the camera is moving):
program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));``` Lastly, the model matrix can be updated per frame if you are animating it: ```program["model_matrix"].SetValue(Matrix4.CreateRotationY(angle) * Matrix4.CreateTranslation(new Vector3(-1.5f, 0, 0)));``` Hopefully this helps! — Reply to this email directly, view it on GitHub <https://github.com/giawa/opengl4csharp/issues/67#issuecomment-1188487858>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AKSGPII3UYI75B3BE42WFELVUX6JFANCNFSM53WJ4RTQ> . You are receiving this because you authored the thread.Message ID: ***@***.***>
program
in this case is the ShaderProgram
that contains your vertex and fragment shader code. ["projection_matrix"]
then performs a lookup and assignment to a uniform
in that shader. In this case, it would be a uniform mat4 projection_matrix
as given in the vertex shader example I provided.
Unfortunately, it looks like that github repo is empty. I'd suggest taking a look at the code here and going from there if you would like to use the opengl4csharp library. https://github.com/giawa/opengl4tutorials
That being said, this looks like you're asking for customer support and this isn't really an issue with the library itself, so I am going to close this issue for now. Hopefully the link above helps!
I intend to animate my rectangle I noticed you were using Visual Studio 2015 and I am using VS2022 and the interface and layout is different but using the following matrices as an example Matrix4 model = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-55.0f)); Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), Width / Height, 0.1f, 100.0f);
I have a rectangle and I want to transform it into a 3D, for a start I want to animate it as you did in your tutorial 4 and then change it to 3D as a cube or cuboid. I want to know where I need to which class store the view, model, and projection matrices and how to bind them and send them to the shader. Let me know if I can share my code with you.