From 81e520e608508839a70953fd0189caea1f216d37 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 8 Dec 2019 10:04:16 +0200 Subject: [PATCH] GL 3.0 should now work for mac - kudos @lishaoxia1985 --- android/assets/jsons/Nations/Nations.json | 4 +- .../Nations/Nations_Simplified_Chinese.json | 2 +- .../jsons/Nations/Nations_Ukrainian.json | 4 +- .../unciv/ui/utils/CameraStageBaseScreen.kt | 42 ++++++++++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/android/assets/jsons/Nations/Nations.json b/android/assets/jsons/Nations/Nations.json index 73d09bb906..0ebcbb54a2 100644 --- a/android/assets/jsons/Nations/Nations.json +++ b/android/assets/jsons/Nations/Nations.json @@ -517,8 +517,8 @@ declaringWar:"Jip-hyun-jun (Hall of Worthies) will no longer tolerate your irksome behavior. We will liberate the citizens under your oppression even with force, and enlighten them!" attacked:"Foolish, miserable wretch! You will be crushed by this country's magnificent scientific power!" - defeated:"Now the question is who will protect my people. A dark age has come." - introduction:"Welcome to the palace of Choson, stanger. I am the learned King Sejong, who looks after his great people." + defeated:"Now the question is who will protect my people. A dark age has come.", + introduction:"Welcome to the palace of Choson, stranger. I am the learned King Sejong, who looks after his great people.", neutralHello:"Hello." neutralLetsHearIt:["I will hear it.","Go on","Continue."] diff --git a/android/assets/jsons/Nations/Nations_Simplified_Chinese.json b/android/assets/jsons/Nations/Nations_Simplified_Chinese.json index 9d0cd57e53..a2e2356607 100644 --- a/android/assets/jsons/Nations/Nations_Simplified_Chinese.json +++ b/android/assets/jsons/Nations/Nations_Simplified_Chinese.json @@ -570,7 +570,7 @@ declaringWar:"Jip-hyun-jun (Hall of Worthies) will no longer tolerate your irksome behavior. We will liberate the citizens under your oppression even with force, and enlighten them!" attacked:"Foolish, miserable wretch! You will be crushed by this country's magnificent scientific power!" defeated:"Now the question is who will protect my people. A dark age has come." - introduction:"Welcome to the palace of Choson, stanger. I am the learned King Sejong, who looks after his great people." + introduction:"Welcome to the palace of Choson, stranger. I am the learned King Sejong, who looks after his great people." neutralHello:"Hello." neutralLetsHearIt:["I will hear it.","Go on","Continue."] diff --git a/android/assets/jsons/Nations/Nations_Ukrainian.json b/android/assets/jsons/Nations/Nations_Ukrainian.json index c20a57445b..58a90dd5ca 100644 --- a/android/assets/jsons/Nations/Nations_Ukrainian.json +++ b/android/assets/jsons/Nations/Nations_Ukrainian.json @@ -532,8 +532,8 @@ declaringWar:"Jip-hyun-jun (Hall of Worthies) will no longer tolerate your irksome behavior. We will liberate the citizens under your oppression even with force, and enlighten them!" attacked:"Foolish, miserable wretch! You will be crushed by this country's magnificent scientific power!" - defeated:"Now the question is who will protect my people. A dark age has come." - introduction:"Welcome to the palace of Choson, stanger. I am the learned King Sejong, who looks after his great people." + defeated:"Now the question is who will protect my people. A dark age has come.", + introduction:"Welcome to the palace of Choson, stranger. I am the learned King Sejong, who looks after his great people.", neutralHello:"Hello." neutralLetsHearIt:["I will hear it.","Go on","Continue."] diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 0c0cffaac9..19083bdf31 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -1,5 +1,6 @@ package com.unciv.ui.utils +import com.badlogic.gdx.Application import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.Screen @@ -7,6 +8,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.scenes.scene2d.* import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.utils.ClickListener @@ -73,7 +75,45 @@ open class CameraStageBaseScreen : Screen { skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(45).apply { data.setScale(20/45f) } skin.get(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE } - internal var batch: Batch = SpriteBatch() + internal var batch: Batch = if(Gdx.app.type == Application.ApplicationType.Android) SpriteBatch() else SpriteBatch(1000, createDefaultShader()) + + // This is so the MacOS works with GL 3.0, see https://github.com/yairm210/Unciv/issues/1428 + fun createDefaultShader(): ShaderProgram? { + val vertexShader = ("#version 330 core\n" + + "in vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" // + + "in vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" // + + "in vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" // + + "uniform mat4 u_projTrans;\n" // + + "out vec4 v_color;\n" // + + "out vec2 v_texCoords;\n" // + + "\n" // + + "void main()\n" // + + "{\n" // + + " v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" // + + " v_color.a = v_color.a * (255.0/254.0);\n" // + + " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" // + + " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" // + + "}\n") + val fragmentShader = ("#version 330 core\n" + + "#ifdef GL_ES\n" // + + "#define LOWP lowp\n" // + + "precision mediump float;\n" // + + "#else\n" // + + "#define LOWP \n" // + + "#endif\n" // + + "in LOWP vec4 v_color;\n" // + + "in vec2 v_texCoords;\n" // + + "out vec4 fragColor;\n" // + + "uniform sampler2D u_texture;\n" // + + "void main()\n" // + + "{\n" // + + " fragColor = v_color * texture(u_texture, v_texCoords);\n" // + + "}") + val shader = ShaderProgram(vertexShader, fragmentShader) + require(shader.isCompiled) { "Error compiling shader: " + shader.log } + return shader + } + } fun onBackButtonClicked(action:()->Unit){