From f46ee1983878cf2d6c532f3a312c3c7e11ba9b8f Mon Sep 17 00:00:00 2001 From: Sunpy Date: Fri, 16 Nov 2018 23:39:12 +0100 Subject: [PATCH] make shader work tm --- res/sh_Cursor.vertex | 4 +- res/sh_Texture.frag | 2 +- src/com/osufx/sunpy/Shader.java | 11 +++- src/com/osufx/sunpy/ShaderProperty.java | 7 +-- src/itdelatrisu/opsu/ui/Cursor.java | 67 ++++++++++++++++++------- 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/res/sh_Cursor.vertex b/res/sh_Cursor.vertex index de9ed955..d882d20b 100644 --- a/res/sh_Cursor.vertex +++ b/res/sh_Cursor.vertex @@ -9,7 +9,7 @@ uniform float g_FadeClock; void main(void) { - gl_Position = m_Position; - v_Color = vec4(1.0, 0.0, 0.0, 1.0); + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //m_Position; + v_Color = vec4(1.0, 0.0, 0.0, g_FadeClock); v_TexCoord = m_TexCoord; } \ No newline at end of file diff --git a/res/sh_Texture.frag b/res/sh_Texture.frag index 06102e68..74856678 100644 --- a/res/sh_Texture.frag +++ b/res/sh_Texture.frag @@ -9,5 +9,5 @@ uniform sampler2D m_Sampler; void main(void) { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);//v_Color * texture2D(m_Sampler, v_TexCoord); + gl_FragColor = v_Color * texture2D(m_Sampler, v_TexCoord); } \ No newline at end of file diff --git a/src/com/osufx/sunpy/Shader.java b/src/com/osufx/sunpy/Shader.java index 6b2af720..ab1b784d 100644 --- a/src/com/osufx/sunpy/Shader.java +++ b/src/com/osufx/sunpy/Shader.java @@ -24,7 +24,7 @@ public class Shader { public static List loadedShaders = new ArrayList<>(); public static int currentShader = 0; - private HashMap attribLoc = new HashMap<>(); + public HashMap attribLoc = new HashMap<>(); private static final String[] attribs = new String[] { "m_Position", "m_Color", @@ -184,6 +184,11 @@ public class Shader { this.previousShader = currentShader; currentShader = this.programId; + GL20.glEnableVertexAttribArray(this.attribLoc.get("m_Position")); + GL20.glEnableVertexAttribArray(this.attribLoc.get("m_TexCoord")); + + //this.Properties.set("m_Sampler", 0); + this.started = true; } @@ -191,6 +196,10 @@ public class Shader { if (!this.started) return; + GL11.glFlush(); + GL20.glDisableVertexAttribArray(this.attribLoc.get("m_TexCoord")); + GL20.glDisableVertexAttribArray(this.attribLoc.get("m_Position")); + GL20.glUseProgram(this.previousShader); currentShader = this.previousShader; diff --git a/src/com/osufx/sunpy/ShaderProperty.java b/src/com/osufx/sunpy/ShaderProperty.java index 7924ce9f..8d610b1a 100644 --- a/src/com/osufx/sunpy/ShaderProperty.java +++ b/src/com/osufx/sunpy/ShaderProperty.java @@ -34,7 +34,7 @@ public class ShaderProperty { GL20.glUniform1(this.Location, IntBuffer.wrap( new int[]{ (int)Value } )); break; case Float: - GL20.glUniform1(this.Location, FloatBuffer.wrap( new float[]{ (float)Value } )); + GL20.glUniform1f(this.Location, (float)Value); break; case BoolVec2: GL20.glUniform2(this.Location, IntBuffer.wrap( boolArrayToIntArray( (boolean[])Value ) )); @@ -43,7 +43,8 @@ public class ShaderProperty { GL20.glUniform2(this.Location, IntBuffer.wrap( (int[])Value )); break; case FloatVec2: - GL20.glUniform2(this.Location, FloatBuffer.wrap( (float[])Value )); + float[] value = (float[])Value; + GL20.glUniform2f(this.Location, value[0], value[1]); break; case FloatMat2: GL20.glUniformMatrix2(this.Location, false, FloatBuffer.wrap( (float[])Value )); @@ -73,7 +74,7 @@ public class ShaderProperty { GL20.glUniformMatrix4(this.Location, false, FloatBuffer.wrap( (float[])Value )); break; case Sampler2D: - GL20.glUniform1(this.Location, BufferUtils.createIntBuffer(1).put((int) Value)); + GL20.glUniform1i(this.Location, (int) Value); break; } } diff --git a/src/itdelatrisu/opsu/ui/Cursor.java b/src/itdelatrisu/opsu/ui/Cursor.java index ad40cd7d..c51f720b 100644 --- a/src/itdelatrisu/opsu/ui/Cursor.java +++ b/src/itdelatrisu/opsu/ui/Cursor.java @@ -30,10 +30,7 @@ import java.util.Iterator; import java.util.LinkedList; import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.EXTFramebufferObject; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL14; +import org.lwjgl.opengl.*; import org.newdawn.slick.*; import org.newdawn.slick.opengl.Texture; import org.newdawn.slick.opengl.TextureImpl; @@ -203,6 +200,8 @@ public class Cursor { float txtw = txt.getWidth(); float txth = txt.getHeight(); + //img.draw(0f,0f); + /* // stuff copied from CurveRenderState and stuff, I don't know what I'm doing int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); @@ -214,34 +213,64 @@ public class Cursor { GL11.glClearColor(0f, 0f, 0f, 0f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); */ - //txt.bind(); - Color.white.bind(); - TextureImpl.unbind(); - cursorTrailShader.Begin(); - GL11.glBegin(GL11.GL_QUADS); + //Color.white.bind(); + + + //GL20.glVertexAttrib4f(cursorTrailShader.attribLoc.get("m_Position"), 1f, 1f, 1f, 1f); + //GL11.glBindTexture(GL11.GL_TEXTURE_2D, ); //cursorTrailShader.Properties.set("m_Sampler", txt.getTextureID()); - //cursorTrailShader.Properties.set("g_FadeClock", 0.4f); + + //GL20.glUniform1i(cursorTrailShader.attribLoc.get("m_Sampler"), txt.getTextureID()); + //IntBuffer buf = BufferUtils.createIntBuffer(1).put(txt.getTextureID()); + + cursorTrailShader.Begin(); + GL13.glActiveTexture(GL13.GL_TEXTURE5); + //GL11.glEnable(GL11.GL_TEXTURE_2D); + //GL11.glGenTextures(); + + + //txt.bind(); + //TextureImpl.unbind(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, txt.getTextureID()); + //GL33.glBindSampler(GL20.GL_SAMPLER_2D, txt.getTextureID()); + //GL20.glUniform1i(cursorTrailShader.attribLoc.get("m_Sampler"), 0); + + //cursorTrailShader.Properties.set("m_TexCoord", new float[] { txtw, txth }); + int idd = GL20.glGetAttribLocation(cursorTrailShader.programId, "m_TexCoord"); + + cursorTrailShader.Properties.set("m_Sampler", 5); + //GL20.glUniform1i(cursorTrailShader.Properties.get("m_Sampler").Location, 5); + + + + cursorTrailShader.Properties.set("g_FadeClock", 0.04f); + GL11.glBegin(GL11.GL_QUADS); float alpha = 0f; float alphaIncrease = .4f / trail.size; for (Trailpart p : trail) { //alpha += alphaIncrease; - GL11.glColor4f(filter.r, filter.g, filter.b, alpha); - //GL11.glTexCoord2f(0f, 0f); + //GL11.glColor4f(filter.r, filter.g, filter.b, 1f); + GL11.glTexCoord2f(0f, 0f); + GL20.glVertexAttrib2f(idd, 0f, 0f); GL11.glVertex3f(p.x - trailw2, p.y - trailh2, 0f); - //GL11.glTexCoord2f(txtw, 0); + GL11.glTexCoord2f(txtw, 0); + GL20.glVertexAttrib2f(idd, txtw, 0); GL11.glVertex3f(p.x + trailw2, p.y - trailh2, 0f); - //GL11.glTexCoord2f(txtw, txth); + GL11.glTexCoord2f(txtw, txth); + GL20.glVertexAttrib2f(idd, txtw, txth); GL11.glVertex3f(p.x + trailw2, p.y + trailh2, 0f); - //GL11.glTexCoord2f(0f, txth); + GL11.glTexCoord2f(0f, txth); + GL20.glVertexAttrib2f(idd, 0f, txth); GL11.glVertex3f(p.x - trailw2, p.y + trailh2, 0f); - break; + //break; } - //GL11.glEnd(); GL11.glEnd(); cursorTrailShader.End(); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + /* GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb); @@ -264,8 +293,8 @@ public class Cursor { GL11.glEnd(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); */ - //CURSOR.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter); - //CURSOR_MIDDLE.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter); + CURSOR.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter); + CURSOR_MIDDLE.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter); } /**