Set Ball Position

https://github.com/kion-dgl/DashGL-GTK-Brickout-Tutorial/tree/master/07_Set_Ball_Position

Set ball position with matrix

A common technique that you will become familiar with in OpenGL is having your assets with local coordinates at the origin. These assets are then positioned into the scene where you need with a model position (mvp) matrix. To do this, we'll edit our vertex shader again.

#version 120

uniform mat4 mvp;
uniform mat4 orthograph;
attribute vec2 coord2d;

void main (void) {
	
	vec4 pixel_pos = mvp * vec4(coord2d, 0.0, 1.0);
	gl_Position = orthograph * pixel_pos;

}

Next we'll add the mvp matrix into our main program.

Compile with:

Run with:

Last updated

Was this helpful?