1- using OpenTK . Graphics . OpenGL4 ;
1+ using MathNet . Numerics . LinearAlgebra ;
2+ using OpenTK . Graphics . OpenGL4 ;
3+ using OpenTK . Mathematics ;
24using OpenTK . Windowing . Desktop ;
35
46namespace FreeFrame . Components . Shapes
57{
68 public abstract class Shape
79 {
8- protected static Window ? _window ;
10+ #region Common Geometry Properties
11+ Color4 _color = new Color4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
12+ #endregion
13+ private static Window ? _window ;
914 private Shader _shader ;
1015 private int _vertexBufferObject ;
1116 private int _vertexArrayObject ;
1217 private int _indexBufferObject ;
1318
1419 private int _indexCount ;
1520
21+ public Color4 Color { get => _color ; set => _color = value ; }
22+
1623 public Shape ( ) { }
1724 public static void BindWindow ( GameWindow window ) => _window = ( Window ) window ;
1825 public void GenerateObjects ( )
@@ -30,8 +37,23 @@ public void GenerateObjects()
3037 /// <param name="index">index array</param>
3138 public void ImplementObjects ( )
3239 {
40+ //float[] vertices =
41+ //{
42+ // 0.5f, 0.5f, // Top-Right
43+ // 0.5f, 0.0f, // Bottom-Right
44+ // 0.0f, 0.0f, // Bottom-Left
45+ // 0.0f, 0.5f, // Top-Left
46+ //};
47+
48+ //uint[] indexes =
49+ //{
50+ // 0, 1, 2, // First triangle
51+ // 0, 2, 3, // Second triangle
52+ //};
53+
3354 float [ ] vertices = GetVertices ( ) ;
3455 uint [ ] indexes = GetVerticesIndexes ( ) ;
56+
3557 // VAO
3658 GL . BindVertexArray ( _vertexArrayObject ) ;
3759
@@ -64,7 +86,20 @@ public void ImplementObjects()
6486 /// </summary>
6587 public void Draw ( )
6688 {
89+ if ( _window == null )
90+ throw new Exception ( "Trying to convert to NDC but no Window is binded" ) ;
91+
6792 _shader . Use ( ) ;
93+
94+ // Applied projection matrix
95+ int uModelToNDC = _shader . GetUniformLocation ( "u_Model_To_NDC" ) ; // TODO: Don't need to apply projection matrix at each frame I think
96+ Matrix4 matrix = Matrix4 . CreateOrthographicOffCenter ( 0 , _window . ClientSize . X , _window . ClientSize . Y , 0 , - 1.0f , 1.0f ) ;
97+ _shader . SetUniformMat4 ( uModelToNDC , matrix ) ;
98+
99+ // Applied common geometry color
100+ int uColor = _shader . GetUniformLocation ( "u_Color" ) ;
101+ _shader . SetUniformVec4 ( uColor , ( Vector4 ) Color ) ;
102+
68103 GL . BindVertexArray ( _vertexArrayObject ) ;
69104 GL . DrawElements ( PrimitiveType . Triangles , _indexCount , DrawElementsType . UnsignedInt , 0 ) ;
70105 }
@@ -85,6 +120,7 @@ public void DeleteObjects()
85120 /// </summary>
86121 /// <returns>array of indexes</returns>
87122 public abstract uint [ ] GetVerticesIndexes ( ) ;
123+ public abstract Hitbox Hitbox ( ) ;
88124 public abstract override string ToString ( ) ;
89125 }
90126
0 commit comments