c++ - How to apply position transformation -


how apply drawing position in world via shaders?

my vertex shader looks this:

in vec2 position;  uniform mat4x4 model; uniform mat4x4 view; uniform mat4x4 projection;  void main() {     gl_position = projection * view * model * vec4(position, 0.0, 1.0); } 

where position positions of vertexes of triangles.

i'm binding matrices follows.

view:

glm::mat4x4 view = glm::lookat(                     glm::vec3(0.0f, 1.2f, 1.2f),    // camera position                     glm::vec3(0.0f, 0.0f, 0.0f),    // camera target                     glm::vec3(0.0f, 0.0f, 1.0f));   // camera axis glint view_uniform = glgetuniformlocation(shader, "view"); gluniformmatrix4fv(view_uniform, 1, gl_false, glm::value_ptr(view)); 

projection:

glm::mat4x4 projection = glm::perspective(80.0f, 640.0f/480.0f, 0.1f, 100.0f); glint projection_uniform = glgetuniformlocation(shader, "projection"); gluniformmatrix4fv(projection_uniform, 1, gl_false, glm::value_ptr(projection)); 

model transformation:

glm::mat4x4 model; model = glm::translate(model, glm::vec3(1.0f, 0.0f, 0.0f)); model = glm::rotate(model, static_cast<float>((glm::sin(currenttime)) * 360.0), glm::vec3(0.0, 0.0, 1.0)); glint trans_uniform = glgetuniformlocation(shader, "model"); gluniformmatrix4fv(trans_uniform, 1, gl_false, glm::value_ptr(model)); 

so way have compute position transformation each frame on cpu. recommended way or there better one?

so way have compute position transformation each frame on cpu. recommended way or there better one?

yes. calculating new transform once mesh on cpu , applying vertices inside mesh inside vertex shader not going slow operation , needs done every frame.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -