@@ -3,7 +3,7 @@ package direct
33import org.lwjgl.BufferUtils
44import org.lwjgl.opengl.GL
55import org.lwjgl.opengl.GL30.*
6- import java.io.File
6+ import java.io.InputStream
77import javax.imageio.ImageIO
88
99// language=glsl
@@ -46,8 +46,8 @@ class SampleRenderer {
4646 if (initialized) return
4747
4848 val img = " image.png"
49- val (id, _) = loadTexture( File ( img))
50- textureId = id
49+ val stream = javaClass.classLoader.getResourceAsStream( img) ? : error( " Resource not found: $img " )
50+ textureId = loadTexture(stream)
5151
5252 shaderProgram = glCreateProgram()
5353 val vertexShader = glCreateShader(GL_VERTEX_SHADER )
@@ -143,8 +143,8 @@ class SampleRenderer {
143143 }
144144}
145145
146- fun loadTexture (file : File ): Pair < Int , Pair < Int , Int >> {
147- val image = ImageIO .read(file )
146+ fun loadTexture (stream : InputStream ): Int {
147+ val image = ImageIO .read(stream )
148148
149149 val width = image.width
150150 val height = image.height
@@ -190,5 +190,5 @@ fun loadTexture(file: File): Pair<Int, Pair<Int, Int>> {
190190 )
191191 glBindTexture(GL_TEXTURE_2D , 0 )
192192
193- return textureID to (width to height)
193+ return textureID
194194}
0 commit comments