diff --git a/assets/textures.go b/assets/textures.go index a40d3b8..fb58ab6 100755 --- a/assets/textures.go +++ b/assets/textures.go @@ -45,6 +45,7 @@ type TextureLoadOptions struct { WriteToCache bool GenMipMaps bool KeepPixelsInMem bool + TextureIsSrgba bool } type Cubemap struct { @@ -102,7 +103,12 @@ func LoadTexturePNG(file string, loadOptions *TextureLoadOptions) (Texture, erro gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) // load and generate the texture - gl.TexImage2D(gl.TEXTURE_2D, 0, gl.SRGB_ALPHA, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) + internalFormat := int32(gl.RGBA8) + if loadOptions.TextureIsSrgba { + internalFormat = gl.SRGB_ALPHA + } + + gl.TexImage2D(gl.TEXTURE_2D, 0, internalFormat, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) if loadOptions.GenMipMaps { gl.GenerateMipmap(tex.TexID) @@ -145,7 +151,12 @@ func LoadTextureInMemPngImg(img image.Image, loadOptions *TextureLoadOptions) (T gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) // load and generate the texture - gl.TexImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) + internalFormat := int32(gl.RGBA8) + if loadOptions.TextureIsSrgba { + internalFormat = gl.SRGB_ALPHA + } + + gl.TexImage2D(gl.TEXTURE_2D, 0, internalFormat, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) if loadOptions.GenMipMaps { gl.GenerateMipmap(tex.TexID) @@ -205,7 +216,12 @@ func LoadTextureJpeg(file string, loadOptions *TextureLoadOptions) (Texture, err gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) // load and generate the texture - gl.TexImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) + internalFormat := int32(gl.RGBA8) + if loadOptions.TextureIsSrgba { + internalFormat = gl.SRGB_ALPHA + } + + gl.TexImage2D(gl.TEXTURE_2D, 0, internalFormat, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0])) if loadOptions.GenMipMaps { gl.GenerateMipmap(tex.TexID) diff --git a/engine/engine.go b/engine/engine.go index 957f53c..d55c891 100755 --- a/engine/engine.go +++ b/engine/engine.go @@ -198,12 +198,22 @@ func initOpenGL() error { gl.FrontFace(gl.CCW) gl.Enable(gl.BLEND) + gl.Enable(gl.FRAMEBUFFER_SRGB) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.ClearColor(0, 0, 0, 1) return nil } +func SetSrgbFramebuffer(isEnabled bool) { + + if isEnabled { + gl.Enable(gl.FRAMEBUFFER_SRGB) + } else { + gl.Disable(gl.FRAMEBUFFER_SRGB) + } +} + func SetVSync(enabled bool) { assert.T(isInited, "engine.Init was not called!") diff --git a/main.go b/main.go index 4c83799..912432e 100755 --- a/main.go +++ b/main.go @@ -213,7 +213,7 @@ func (g *OurGame) Init() { skyboxMat = materials.NewMaterial("Skybox mat", "./res/shaders/skybox.glsl") //Load meshes - cubeMesh, err = meshes.NewMesh("Cube", "./res/models/tex-cube.fbx", 0) + cubeMesh, err = meshes.NewMesh("Cube", "./res/models/plane.fbx", 0) if err != nil { logging.ErrLog.Fatalln("Failed to load mesh. Err: ", err) } @@ -229,7 +229,7 @@ func (g *OurGame) Init() { } //Load textures - tex, err := assets.LoadTexturePNG("./res/textures/pallete-endesga-64-1x.png", nil) + tex, err := assets.LoadTexturePNG("./res/textures/logo - black bg.png", nil) if err != nil { logging.ErrLog.Fatalln("Failed to load texture. Err: ", err) } @@ -383,6 +383,7 @@ func (g *OurGame) Render() { tempModelMatrix := cubeModelMat.Clone() window.Rend.Draw(chairMesh, tempModelMatrix, matToUse) + tempModelMatrix.Rotate(90*gglm.Deg2Rad, gglm.NewVec3(0, 1, 0)) rowSize := 1 for y := 0; y < rowSize; y++ { for x := 0; x < rowSize; x++ { diff --git a/res/models/plane.fbx b/res/models/plane.fbx new file mode 100755 index 0000000..d3fc6ec Binary files /dev/null and b/res/models/plane.fbx differ diff --git a/ui/imgui/imgui.go b/ui/imgui/imgui.go index eb735c3..994fb04 100755 --- a/ui/imgui/imgui.go +++ b/ui/imgui/imgui.go @@ -67,7 +67,7 @@ func (i *ImguiInfo) Render(winWidth, winHeight float32, fbWidth, fbHeight int32) i.Mat.Bind() i.Mat.SetUnifInt32("Texture", 0) - //PERF: only update the ortho matrix on window resize + // @PERF: only update the ortho matrix on window resize orthoMat := gglm.Ortho(0, float32(winWidth), 0, float32(winHeight), 0, 20) i.Mat.SetUnifMat4("ProjMtx", &orthoMat.Mat4) gl.BindSampler(0, 0) // Rely on combined texture/sampler state.