Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41facb9

Browse filesBrowse files
committed
up
1 parent bfa169b commit 41facb9
Copy full SHA for 41facb9

File tree

Expand file treeCollapse file tree

11 files changed

+564
-74
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+564
-74
lines changed

‎gradle/wrapper/gradle-wrapper.properties

Copy file name to clipboardExpand all lines: gradle/wrapper/gradle-wrapper.properties
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

‎src/main/kotlin/learnOpenGL/common/util.kt

Copy file name to clipboardExpand all lines: src/main/kotlin/learnOpenGL/common/util.kt
+51-7Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package learnOpenGL.common
22

3+
import gli_.Format
4+
import gli_.Target
5+
import gli_.Texture
36
import gli_.gl
47
import gli_.gli
8+
import glm_.set
9+
import glm_.vec3.Vec3i
510
import gln.texture.glTexImage2D
611
import org.lwjgl.opengl.GL11
12+
import org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE
13+
import org.lwjgl.opengl.GL12.GL_TEXTURE_WRAP_R
14+
import org.lwjgl.opengl.GL13.GL_TEXTURE_CUBE_MAP
715
import org.lwjgl.opengl.GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X
816
import org.lwjgl.opengl.GL30
917
import uno.buffer.toBuf
@@ -12,6 +20,8 @@ import uno.kotlin.uri
1220
import java.awt.image.BufferedImage
1321
import java.awt.image.DataBufferByte
1422
import java.io.File
23+
import java.nio.file.Path
24+
import java.nio.file.Paths
1525
import javax.imageio.ImageIO
1626

1727

@@ -81,27 +91,61 @@ fun loadTexture(path: String): Int {
8191
fun loadCubemap(path: String, extension: String): Int {
8292

8393
val textureID = GL11.glGenTextures()
84-
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID)
94+
GL11.glBindTexture(GL_TEXTURE_CUBE_MAP, textureID)
8595

8696
listOf("right", "left", "top", "bottom", "back", "front").forEachIndexed { i, it ->
8797

88-
val texture = gli.load("$path/$it.$extension".uri)
98+
//val texture = gli.load("$path/$it.$extension".uri)
99+
val texture = loadImage(Paths.get("$path/$it.$extension".uri))
89100
gli.gl.profile = gl.Profile.GL33
90101
val format = gli.gl.translate(texture.format, texture.swizzles)
91102

92103
val extend = texture.extent()
93104
GL11.glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format.internal.i,
94105
extend.x, extend.y, 0, format.external.i, format.type.i, texture.data())
95106

96-
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D)
107+
GL30.glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
97108

98-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT)
99-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT)
100-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR)
101-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR)
109+
GL11.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
110+
GL11.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
111+
GL11.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)
112+
GL11.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR)
113+
GL11.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR)
102114

103115
texture.dispose()
104116
}
105117

106118
return textureID
119+
}
120+
121+
//TODO remove this shit, remove .flipY() on first line and remove it from gli and all the tests here
122+
fun loadImage(path: Path): Texture {
123+
val image = ImageIO.read(path.toFile())
124+
val data = (image.raster.dataBuffer as DataBufferByte).data
125+
val format = when (image.type) {
126+
BufferedImage.TYPE_3BYTE_BGR -> { // switch blue and red
127+
repeat(image.width * image.height) {
128+
val tmp = data[it * 3] // save blue
129+
data[it * 3] = data[it * 3 + 2] // write red
130+
data[it * 3 + 2] = tmp // write blue
131+
}
132+
Format.RGB8_UNORM_PACK8
133+
}
134+
BufferedImage.TYPE_4BYTE_ABGR -> {
135+
repeat(image.width * image.height) {
136+
// switch alpha and red
137+
var tmp = data[it * 4] // save alpha
138+
data[it * 4] = data[it * 4 + 3] // write red
139+
data[it * 4 + 3] = tmp // write alpha
140+
// switch blue and green
141+
tmp = data[it * 4 + 1] // save blue
142+
data[it * 4 + 1] = data[it * 4 + 2] // write green
143+
data[it * 4 + 2] = tmp // write blue
144+
}
145+
Format.RGBA8_UNORM_PACK8
146+
}
147+
else -> throw Error("not yet supported")
148+
}
149+
return Texture(Target._2D, format, Vec3i(image.width, image.height, 1), 1, 1, 1)
150+
.apply { with(data()) { for (i in 0 until size) set(i, data[i]) } }
107151
}

‎src/main/kotlin/learnOpenGL/d_advancedOpenGL/5.1 framebuffers.kt

Copy file name to clipboardExpand all lines: src/main/kotlin/learnOpenGL/d_advancedOpenGL/5.1 framebuffers.kt
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import gln.draw.glDrawArrays
1111
import gln.framebuffer.glBindFramebuffer
1212
import gln.framebuffer.glFramebufferRenderbuffer
1313
import gln.get
14+
import gln.glClearColor
1415
import gln.glf.glf
1516
import gln.glf.semantic
1617
import gln.program.usingProgram
@@ -26,6 +27,7 @@ import learnOpenGL.a_gettingStarted.end
2627
import learnOpenGL.a_gettingStarted.swapAndPoll
2728
import learnOpenGL.a_gettingStarted.windowSize
2829
import learnOpenGL.b_lighting.camera
30+
import learnOpenGL.b_lighting.clearColor0
2931
import learnOpenGL.b_lighting.initWindow0
3032
import learnOpenGL.b_lighting.processFrame
3133
import learnOpenGL.common.loadTexture
@@ -41,6 +43,7 @@ import uno.glsl.Program
4143
import uno.glsl.glDeletePrograms
4244
import uno.glsl.glUseProgram
4345
import uno.glsl.usingProgram
46+
import java.awt.Color
4447

4548

4649
fun main(args: Array<String>) {
@@ -162,7 +165,7 @@ private class Framebuffers {
162165
glEnable(GL_DEPTH_TEST) // enable depth testing (is disabled for rendering screen-space quad)
163166

164167
// make sure we clear the framebuffer's content
165-
glClearColor(0.1f, 0.1f, 0.1f, 1.0f)
168+
glClearColor(clearColor0)
166169
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
167170

168171
glUseProgram(programRender)
@@ -193,7 +196,7 @@ private class Framebuffers {
193196
glBindFramebuffer(GL_FRAMEBUFFER, 0)
194197
glDisable(GL_DEPTH_TEST) // disable depth test so screen-space quad isn't discarded due to depth test.
195198
// clear all relevant buffers
196-
glClearColor(1f, 1f, 1f, 1f) // not really necessary actually, since we won't be able to see behind the quad anyways
199+
glClearColor(Color.white) // not really necessary actually, since we won't be able to see behind the quad anyways
197200
glClear(GL_COLOR_BUFFER_BIT)
198201

199202
glUseProgram(programSplash)

‎src/main/kotlin/learnOpenGL/d_advancedOpenGL/6.1 cubemaps skybox.kt

Copy file name to clipboardExpand all lines: src/main/kotlin/learnOpenGL/d_advancedOpenGL/6.1 cubemaps skybox.kt
+63-62Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ package learnOpenGL.d_advancedOpenGL
77
import glm_.func.rad
88
import glm_.glm
99
import glm_.mat4x4.Mat4
10+
import gln.draw.glDrawArrays
1011
import gln.get
12+
import gln.glClearColor
1113
import gln.glf.glf
1214
import gln.glf.semantic
1315
import gln.program.usingProgram
@@ -16,10 +18,12 @@ import gln.uniform.glUniform
1618
import gln.vertexArray.glBindVertexArray
1719
import gln.vertexArray.glEnableVertexAttribArray
1820
import gln.vertexArray.glVertexAttribPointer
21+
import gln.vertexArray.withVertexArray
1922
import learnOpenGL.a_gettingStarted.end
2023
import learnOpenGL.a_gettingStarted.swapAndPoll
2124
import learnOpenGL.a_gettingStarted.verticesCube
2225
import learnOpenGL.b_lighting.camera
26+
import learnOpenGL.b_lighting.clearColor0
2327
import learnOpenGL.b_lighting.initWindow0
2428
import learnOpenGL.b_lighting.processFrame
2529
import learnOpenGL.common.loadCubemap
@@ -44,9 +48,52 @@ fun main(args: Array<String>) {
4448
}
4549
}
4650

51+
val verticesSkybox = floatArrayOf( // positions
52+
-1f, +1f, -1f,
53+
-1f, -1f, -1f,
54+
+1f, -1f, -1f,
55+
+1f, -1f, -1f,
56+
+1f, +1f, -1f,
57+
-1f, +1f, -1f,
58+
59+
-1f, -1f, +1f,
60+
-1f, -1f, -1f,
61+
-1f, +1f, -1f,
62+
-1f, +1f, -1f,
63+
-1f, +1f, +1f,
64+
-1f, -1f, +1f,
65+
66+
+1f, -1f, -1f,
67+
+1f, -1f, +1f,
68+
+1f, +1f, +1f,
69+
+1f, +1f, +1f,
70+
+1f, +1f, -1f,
71+
+1f, -1f, -1f,
72+
73+
-1f, -1f, +1f,
74+
-1f, +1f, +1f,
75+
+1f, +1f, +1f,
76+
+1f, +1f, +1f,
77+
+1f, -1f, +1f,
78+
-1f, -1f, +1f,
79+
80+
-1f, +1f, -1f,
81+
+1f, +1f, -1f,
82+
+1f, +1f, +1f,
83+
+1f, +1f, +1f,
84+
-1f, +1f, +1f,
85+
-1f, +1f, -1f,
86+
87+
-1f, -1f, -1f,
88+
-1f, -1f, +1f,
89+
+1f, -1f, -1f,
90+
+1f, -1f, -1f,
91+
-1f, -1f, +1f,
92+
+1f, -1f, +1f)
93+
4794
private class CubemapsSkybox {
4895

49-
val window = initWindow0("Framebuffers")
96+
val window = initWindow0("Cubemaps Skybox")
5097

5198
val program = ProgramA()
5299
val skyboxProgram = ProgramSkybox()
@@ -55,53 +102,7 @@ private class CubemapsSkybox {
55102

56103
val vao = intBufferBig<Object>()
57104
val vbo = intBufferBig<Object>()
58-
59-
enum class Tex { Cube, Cubemap }
60-
61-
val tex = intBufferBig<Tex>()
62-
63-
val skyboxVertices = floatArrayOf( // positions
64-
-1f, +1f, -1f,
65-
-1f, -1f, -1f,
66-
+1f, -1f, -1f,
67-
+1f, -1f, -1f,
68-
+1f, +1f, -1f,
69-
-1f, +1f, -1f,
70-
71-
-1f, -1f, +1f,
72-
-1f, -1f, -1f,
73-
-1f, +1f, -1f,
74-
-1f, +1f, -1f,
75-
-1f, +1f, +1f,
76-
-1f, -1f, +1f,
77-
78-
+1f, -1f, -1f,
79-
+1f, -1f, +1f,
80-
+1f, +1f, +1f,
81-
+1f, +1f, +1f,
82-
+1f, +1f, -1f,
83-
+1f, -1f, -1f,
84-
85-
-1f, -1f, +1f,
86-
-1f, +1f, +1f,
87-
+1f, +1f, +1f,
88-
+1f, +1f, +1f,
89-
+1f, -1f, +1f,
90-
-1f, -1f, +1f,
91-
92-
-1f, +1f, -1f,
93-
+1f, +1f, -1f,
94-
+1f, +1f, +1f,
95-
+1f, +1f, +1f,
96-
-1f, +1f, +1f,
97-
-1f, +1f, -1f,
98-
99-
-1f, -1f, -1f,
100-
-1f, -1f, +1f,
101-
+1f, -1f, -1f,
102-
+1f, -1f, -1f,
103-
-1f, -1f, +1f,
104-
+1f, -1f, +1f)
105+
val tex = intBufferBig<Object>()
105106

106107
open inner class ProgramA : ProgramSkybox("cubemaps") {
107108
val model = glGetUniformLocation(name, "model")
@@ -132,15 +133,15 @@ private class CubemapsSkybox {
132133
glEnableVertexAttribArray(glf.pos3_tc2)
133134
glVertexAttribPointer(glf.pos3_tc2)
134135
} else {
135-
glBufferData(GL_ARRAY_BUFFER, skyboxVertices, GL_STATIC_DRAW)
136+
glBufferData(GL_ARRAY_BUFFER, verticesSkybox, GL_STATIC_DRAW)
136137
glEnableVertexAttribArray(glf.pos3)
137138
glVertexAttribPointer(glf.pos3)
138139
}
139140
glBindVertexArray()
140141
}
141142
// load textures
142-
tex[Tex.Cube] = loadTexture("textures/marble.jpg")
143-
tex[Tex.Cubemap] = loadCubemap("textures/skybox", "jpg")
143+
tex[Object.Cube] = loadTexture("textures/marble.jpg")
144+
tex[Object.Skybox] = loadCubemap("textures/skybox", "jpg")
144145
}
145146

146147

@@ -151,7 +152,7 @@ private class CubemapsSkybox {
151152
window.processFrame()
152153

153154

154-
glClearColor(0.1f, 0.1f, 0.1f, 1f)
155+
glClearColor(clearColor0)
155156
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
156157

157158
// draw scene as normal
@@ -163,11 +164,11 @@ private class CubemapsSkybox {
163164
glUniform(program.view, view)
164165
glUniform(program.proj, projection)
165166
// cubes
166-
glBindVertexArray(vao[Object.Cube])
167-
glActiveTexture(GL_TEXTURE0)
168-
glBindTexture(GL_TEXTURE_2D, tex[Tex.Cube])
169-
glDrawArrays(GL_TRIANGLES, 0, 36)
170-
glBindVertexArray()
167+
withVertexArray(vao[Object.Cube]) {
168+
glActiveTexture(GL_TEXTURE0 + semantic.sampler.DIFFUSE)
169+
glBindTexture(GL_TEXTURE_2D, tex[Object.Cube])
170+
glDrawArrays(GL_TRIANGLES, 36)
171+
}
171172

172173
// draw skybox as last
173174
glDepthFunc(GL_LEQUAL) // change depth function so depth test passes when values are equal to depth buffer's content
@@ -176,11 +177,11 @@ private class CubemapsSkybox {
176177
glUniform(skyboxProgram.view, view)
177178
glUniform(skyboxProgram.proj, projection)
178179
// skybox cube
179-
glBindVertexArray(vao[Object.Skybox])
180-
glActiveTexture(GL_TEXTURE0)
181-
glBindTexture(GL_TEXTURE_CUBE_MAP, tex[Tex.Cubemap])
182-
glDrawArrays(GL_TRIANGLES, 0, 36)
183-
glBindVertexArray(0)
180+
withVertexArray(vao[Object.Skybox]) {
181+
glActiveTexture(GL_TEXTURE0 + semantic.sampler.DIFFUSE)
182+
glBindTexture(GL_TEXTURE_CUBE_MAP, tex[Object.Skybox])
183+
glDrawArrays(GL_TRIANGLES, 36)
184+
}
184185
glDepthFunc(GL_LESS) // set depth function back to default
185186

186187

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.