Skip to content

Commit 51a76f5

Browse files
author
Raed Atoui
committed
cleanups
1 parent c95ec73 commit 51a76f5

File tree

5 files changed

+20
-39
lines changed

5 files changed

+20
-39
lines changed

sections/getstarted/4.textures.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func (ht *HelloTextures) getShaders() []string {
1818
return []string{"_assets/getting_started/4.textures/texture.vs",
1919
"_assets/getting_started/4.textures/texture.frag"}
2020
}
21-
2221
func (ht *HelloTextures) getVertices() []float32 {
2322
return []float32{
2423
// Positions // Colors // Texture Coords
@@ -28,7 +27,6 @@ func (ht *HelloTextures) getVertices() []float32 {
2827
-0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Top Left
2928
}
3029
}
31-
3230
func (ht *HelloTextures) createBuffers(vertices []float32) {
3331
indices := []uint32{ // Note that we start from 0!
3432
0, 1, 3, // First Triangle
@@ -49,7 +47,6 @@ func (ht *HelloTextures) createBuffers(vertices []float32) {
4947
}
5048
ht.va.Setup()
5149
}
52-
5350
func (ht *HelloTextures) InitGL() error {
5451
ht.Name = "4. Textures"
5552

@@ -118,7 +115,6 @@ func (ht *TexturesEx1) getShaders() []string {
118115
return []string{"_assets/getting_started/4.textures/texture.vs",
119116
"_assets/getting_started/4.textures/textureex1.frag"}
120117
}
121-
122118
func (ht *TexturesEx1) InitGL() error {
123119
ht.Name = "4a. Textures Ex1"
124120

@@ -169,7 +165,6 @@ func (ht *TexturesEx2) getVertices() []float32 {
169165
-0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 2.0, // Top Left
170166
}
171167
}
172-
173168
func (ht *TexturesEx2) InitGL() error {
174169
ht.Name = "4b. Textures Ex2"
175170

@@ -220,7 +215,6 @@ func (ht *TexturesEx3) getVertices() []float32 {
220215
-0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.45, 0.55, // Top Left
221216
}
222217
}
223-
224218
func (ht *TexturesEx3) InitGL() error {
225219
ht.Name = "4c. Textures Ex3"
226220

@@ -263,7 +257,6 @@ func (ht *TexturesEx4) getShaders() []string {
263257
return []string{"_assets/getting_started/4.textures/texture.vs",
264258
"_assets/getting_started/4.textures/textureex4.frag"}
265259
}
266-
267260
func (ht *TexturesEx4) InitGL() error {
268261
ht.Name = "4d. Textures Ex4"
269262

sections/getstarted/6.coordinates.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func (hc *HelloCoordinates) createBuffers() error {
106106
}
107107
return nil
108108
}
109-
110109
func (hc *HelloCoordinates) createTextures() error {
111110
// Texture 1
112111
if tex, err := glutils.NewTexture(gl.REPEAT, gl.REPEAT, gl.LINEAR, gl.LINEAR, "_assets/images/container.png"); err != nil {
@@ -123,7 +122,6 @@ func (hc *HelloCoordinates) createTextures() error {
123122
}
124123
return nil
125124
}
126-
127125
func (hc *HelloCoordinates) InitGL() error {
128126
if err := hc.createShader(); err != nil {
129127
return err
@@ -161,7 +159,6 @@ func (hc *HelloCoordinates) setTransformations() {
161159
// but since the projection matrix rarely changes it's often best practice to set it outside the main loop only once.
162160
gl.UniformMatrix4fv(hc.shader.Uniforms["projection"], 1, false, &projection[0])
163161
}
164-
165162
func (hc *HelloCoordinates) renderVertexArray() {
166163
// Draw container
167164
gl.BindVertexArray(hc.va.Vao)

sections/lighting/1.colors.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func (lc *LightingColors) initShaders(v1, f1, v2, f2 string) error {
4242
}
4343
return nil
4444
}
45-
4645
func (lc *LightingColors) initCamera() {
4746
// Camera
4847
lc.camera = glutils.NewCamera(
@@ -65,7 +64,6 @@ func (lc *LightingColors) initCamera() {
6564
lc.scaleMat = mgl32.Scale3D(0.2, 0.2, 0.2)
6665
lc.rotationAxis = mgl32.Vec3{1.0, 0.3, 0.5}.Normalize()
6766
}
68-
6967
func (lc *LightingColors) getVertices() []float32 {
7068
return []float32{
7169
-0.5, -0.5, -0.5,
@@ -111,7 +109,6 @@ func (lc *LightingColors) getVertices() []float32 {
111109
-0.5, 0.5, -0.5,
112110
}
113111
}
114-
115112
func (lc *LightingColors) initContainers(vertices []float32) {
116113

117114
attr := glutils.NewAttributesMap()
@@ -136,7 +133,6 @@ func (lc *LightingColors) initContainers(vertices []float32) {
136133
}
137134
lc.lightVa.Setup()
138135
}
139-
140136
func (lc *LightingColors) InitGL() error {
141137
lc.initCamera()
142138
if err := lc.initShaders(
@@ -170,25 +166,23 @@ func (lc *LightingColors) Update() {
170166
lc.camera.ProcessKeyboard(glutils.RIGHT, lc.deltaTime)
171167
}
172168
}
169+
173170
func (lc *LightingColors) clear() {
174171
// Clear the colorbuffer
175172
gl.ClearColor(lc.Color32.R, lc.Color32.G, lc.Color32.B, lc.Color32.A)
176173
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
177174
}
178-
179175
func (lc *LightingColors) setLightingUniforms() {
180176
// Use corresponding shader when setting uniforms/drawing objects
181177
gl.Uniform3f(lc.lightingShader.Uniforms["objectColor"], 1.0, 0.5, 0.31)
182178
gl.Uniform3f(lc.lightingShader.Uniforms["lightColor"], 1.0, 0.5, 1.0)
183179
}
184-
185180
func (lc *LightingColors) getCameraTransforms() (mgl32.Mat4, mgl32.Mat4) {
186181
// Create camera transformations
187182
view := lc.camera.GetViewMatrix()
188183
projection := mgl32.Perspective(float32(lc.camera.Zoom), sections.RATIO, 0.1, 100.0)
189184
return view, projection
190185
}
191-
192186
func (lc *LightingColors) transformShader(shader glutils.Shader, view, projection mgl32.Mat4) {
193187
// Pass the matrices to the shader
194188
gl.UniformMatrix4fv(shader.Uniforms["view"], 1, false, &view[0])
@@ -213,7 +207,6 @@ func (lc *LightingColors) drawLamp() {
213207
gl.DrawArrays(gl.TRIANGLES, 0, 36)
214208
gl.BindVertexArray(0)
215209
}
216-
217210
func (lc *LightingColors) Draw() {
218211
lc.clear()
219212
gl.UseProgram(lc.lightingShader.Program)

sections/lighting/2.basic.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func (lc *BasicSpecular) getVertices() []float32 {
5858
-0.5, 0.5, -0.5, 0.0, 1.0, 0.0,
5959
}
6060
}
61-
6261
func (bc *BasicSpecular) initContainers(vertices []float32) {
6362

6463
attr := glutils.NewAttributesMap()
@@ -85,6 +84,12 @@ func (bc *BasicSpecular) initContainers(vertices []float32) {
8584
bc.lightVa.Setup()
8685
}
8786

87+
func (bc *BasicSpecular) setLightingUniforms() {
88+
gl.Uniform3f(bc.lightingShader.Uniforms["objectColor"], 1.0, 0.5, 0.31)
89+
gl.Uniform3f(bc.lightingShader.Uniforms["lightColor"], 1.0, 0.5, 1.0)
90+
gl.Uniform3f(bc.lightingShader.Uniforms["lightPos"], bc.lightPos[0], bc.lightPos[1], bc.lightPos[2])
91+
gl.Uniform3f(bc.lightingShader.Uniforms["viewPos"], bc.camera.Position[0], bc.camera.Position[1], bc.camera.Position[2])
92+
}
8893
func (bc *BasicSpecular) InitGL() error {
8994
bc.initCamera()
9095
if err := bc.initShaders(
@@ -98,12 +103,6 @@ func (bc *BasicSpecular) InitGL() error {
98103
bc.initContainers(bc.getVertices())
99104
return nil
100105
}
101-
func (bc *BasicSpecular) setLightingUniforms() {
102-
gl.Uniform3f(bc.lightingShader.Uniforms["objectColor"], 1.0, 0.5, 0.31)
103-
gl.Uniform3f(bc.lightingShader.Uniforms["lightColor"], 1.0, 0.5, 1.0)
104-
gl.Uniform3f(bc.lightingShader.Uniforms["lightPos"], bc.lightPos[0], bc.lightPos[1], bc.lightPos[2])
105-
gl.Uniform3f(bc.lightingShader.Uniforms["viewPos"], bc.camera.Position[0], bc.camera.Position[1], bc.camera.Position[2])
106-
}
107106

108107
func (bc *BasicSpecular) Draw() {
109108
bc.clear()

sections/lighting/3.materials.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ func (m *Materials) GetHeader() string {
1616
return "2. Basic Specular Lighting"
1717
}
1818

19-
func (m *Materials) InitGL() error {
20-
m.initCamera()
21-
if err := m.initShaders(
22-
"_assets/lighting/3.materials/materials.vs",
23-
"_assets/lighting/3.materials/materials.frag",
24-
"_assets/lighting/3.materials/lamp.vs",
25-
"_assets/lighting/3.materials/lamp.frag",
26-
); err != nil {
27-
return err
28-
}
29-
m.initContainers(m.getVertices())
30-
return nil
31-
}
32-
3319
func (m *Materials) setLightingUniforms() {
3420
gl.Uniform3f(m.lightingShader.Uniforms["light.position"], m.lightPos.X(), m.lightPos.Y(), m.lightPos.Z())
3521
gl.Uniform3f(m.lightingShader.Uniforms["viewPos"], m.camera.Position.X(), m.camera.Position.Y(), m.camera.Position.Z())
@@ -63,6 +49,19 @@ func (m *Materials) setLightingUniforms() {
6349
gl.Uniform3f(m.lightingShader.Uniforms["material.specular"], 0.5, 0.5, 0.5) // Specular doesn't have full effect on this object's material
6450
gl.Uniform1f(m.lightingShader.Uniforms["material.shininess"], 32.0)
6551
}
52+
func (m *Materials) InitGL() error {
53+
m.initCamera()
54+
if err := m.initShaders(
55+
"_assets/lighting/3.materials/materials.vs",
56+
"_assets/lighting/3.materials/materials.frag",
57+
"_assets/lighting/3.materials/lamp.vs",
58+
"_assets/lighting/3.materials/lamp.frag",
59+
); err != nil {
60+
return err
61+
}
62+
m.initContainers(m.getVertices())
63+
return nil
64+
}
6665

6766
func (m *Materials) Draw() {
6867
m.clear()

0 commit comments

Comments
 (0)