Java Code Examples for org.lwjgl.opengl.GL20#glGetUniformLocation()
The following examples show how to use
org.lwjgl.opengl.GL20#glGetUniformLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericShader.java From LWJGUI with MIT License | 5 votes |
public GenericShader(URL vertexShader, URL fragmentShader) { // make the shader vertexId = compileShader(vertexShader, true); fragmentId = compileShader(fragmentShader, false); posLoc = 0; texCoordLoc = 1; id = createProgram( vertexId, new int[] { fragmentId }, new String[] { "inPos", "inTexCoord" }, new int[] { posLoc, texCoordLoc } ); projMatLoc = GL20.glGetUniformLocation(id, "projectionMatrix"); viewMatLoc = GL20.glGetUniformLocation(id, "viewMatrix"); worldMatLoc = GL20.glGetUniformLocation(id, "worldMatrix"); // Generic white texture texId = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); int wid = 1; int hei = 1; ByteBuffer data = BufferUtils.createByteBuffer(wid*hei*4); while(data.hasRemaining()) { data.put((byte) (255 & 0xff)); } data.flip(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, wid, hei, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); }
Example 2
Source File: ShaderArgs.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Bind args. * * @param program the program */ public void bindArgs(int program) { for(int i=0; i<args.length; i++) { int loc = GL20.glGetUniformLocation(program, "arg"+i); GL20.glUniform1f(loc, args[i]); } }
Example 3
Source File: GLShader.java From ldparteditor with MIT License | 5 votes |
public int getUniformLocation(String uniformName) { int location = uniformMap.getOrDefault(uniformName, -1); if (location == -1) { location = GL20.glGetUniformLocation(program, uniformName); } if (location != -1) { uniformMap.put(uniformName, location); } else { NLogger.error(GLShader.class, "Could not find uniform variable: " + uniformName + "\n" + GL20.glGetProgramInfoLog(program, 1024)); //$NON-NLS-1$ //$NON-NLS-2$; } return location; }
Example 4
Source File: Uniform.java From LowPolyWater with The Unlicense | 4 votes |
protected void storeUniformLocation(int programID){ location = GL20.glGetUniformLocation(programID, name); if(location == NOT_FOUND){ System.err.println("No uniform variable called \"" + name + "\" found for shader program: "+programID); } }
Example 5
Source File: Uniform.java From OpenGL-Animation with The Unlicense | 4 votes |
protected void storeUniformLocation(int programID){ location = GL20.glGetUniformLocation(programID, name); if(location == NOT_FOUND){ System.err.println("No uniform variable called " + name + " found!"); } }
Example 6
Source File: OpenGLRenderer20.java From ldparteditor with MIT License | 4 votes |
/** * Initializes the Scene and gives OpenGL-Hints */ @Override public void init() { // MARK OpenGL Hints and Initialization GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthFunc(GL11.GL_LESS); GL11.glClearDepth(1.0f); GL11.glClearColor(View.background_Colour_r[0], View.background_Colour_g[0], View.background_Colour_b[0], 1.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glPointSize(5); // GL11.glLineWidth(2); GL11.glEnable(GL11.GL_LIGHTING); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glEnable(GL11.GL_NORMALIZE); GL11.glEnable(GL11.GL_LIGHT0); GL11.glEnable(GL11.GL_LIGHT1); GL11.glEnable(GL11.GL_LIGHT2); GL11.glEnable(GL11.GL_LIGHT3); GL11.glLightModelfv(GL11.GL_LIGHT_MODEL_AMBIENT, BufferFactory.floatBuffer(new float[] { 0.1f, 0.1f, 0.1f, 1f })); GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light1_Colour_r[0], View.light1_Colour_g[0], View.light1_Colour_b[0], 1f })); GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light1_specular_Colour_r[0], View.light1_specular_Colour_g[0], View.light1_specular_Colour_b[0], 1f })); GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_LINEAR_ATTENUATION, .001f); GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light2_Colour_r[0], View.light2_Colour_g[0], View.light2_Colour_b[0], 1f })); GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light2_specular_Colour_r[0], View.light2_specular_Colour_g[0], View.light2_specular_Colour_b[0], 1f })); GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_LINEAR_ATTENUATION, .001f); GL11.glLightfv(GL11.GL_LIGHT2, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light3_Colour_r[0], View.light3_Colour_g[0], View.light3_Colour_b[0], 1f })); GL11.glLightfv(GL11.GL_LIGHT2, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light3_specular_Colour_r[0], View.light3_specular_Colour_g[0], View.light3_specular_Colour_b[0], 1f })); GL11.glLightf(GL11.GL_LIGHT2, GL11.GL_LINEAR_ATTENUATION, .001f); GL11.glLightfv(GL11.GL_LIGHT3, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light4_Colour_r[0], View.light4_Colour_g[0], View.light4_Colour_b[0], 1f })); GL11.glLightfv(GL11.GL_LIGHT3, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light4_specular_Colour_r[0], View.light4_specular_Colour_g[0], View.light4_specular_Colour_b[0], 1f })); GL11.glLightf(GL11.GL_LIGHT3, GL11.GL_LINEAR_ATTENUATION, .001f); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE); GL11.glMaterialfv(GL11.GL_FRONT, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { 1.0f, 1.0f, 1.0f, 1.0f })); GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f); GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); if (fsGlossId == -1) { vsGlossId = loadGlossVertexShader(); fsGlossId = loadGlossFragmentShader(); if (pGlossId == -1 && vsGlossId != -1 && fsGlossId != -1) { pGlossId = GL20.glCreateProgram(); GL20.glAttachShader(pGlossId, vsGlossId); GL20.glAttachShader(pGlossId, fsGlossId); GL20.glLinkProgram(pGlossId); GL20.glValidateProgram(pGlossId); baseImageLoc = GL20.glGetUniformLocation(pGlossId, "colorMap"); //$NON-NLS-1$ glossMapLoc = GL20.glGetUniformLocation(pGlossId, "glossMap"); //$NON-NLS-1$ cubeMapLoc = GL20.glGetUniformLocation(pGlossId, "cubeMap"); //$NON-NLS-1$ cubeMapMatteLoc = GL20.glGetUniformLocation(pGlossId, "cubeMapMatte"); //$NON-NLS-1$ cubeMapMetalLoc = GL20.glGetUniformLocation(pGlossId, "cubeMapMetal"); //$NON-NLS-1$ alphaSwitchLoc = GL20.glGetUniformLocation(pGlossId, "alphaSwitch"); //$NON-NLS-1$ normalSwitchLoc = GL20.glGetUniformLocation(pGlossId, "normalSwitch"); //$NON-NLS-1$ noTextureSwitch = GL20.glGetUniformLocation(pGlossId, "noTextureSwitch"); //$NON-NLS-1$ noGlossMapSwitch = GL20.glGetUniformLocation(pGlossId, "noGlossMapSwitch"); //$NON-NLS-1$ cubeMapSwitch = GL20.glGetUniformLocation(pGlossId, "cubeMapSwitch"); //$NON-NLS-1$ noLightSwitch = GL20.glGetUniformLocation(pGlossId, "noLightSwitch"); //$NON-NLS-1$ } } }
Example 7
Source File: LWJGL20DrawContext.java From settlers-remake with MIT License | 4 votes |
private ShaderProgram(String name) { int vertexShader = -1; int fragmentShader; String vname = name; if(name.contains("-")) vname = name.split("-")[0]; try { vertexShader = createShader(vname+".vert", GL20.GL_VERTEX_SHADER); fragmentShader = createShader(name+".frag", GL20.GL_FRAGMENT_SHADER); } catch (IOException e) { e.printStackTrace(); if(vertexShader != -1) GL20.glDeleteShader(vertexShader); throw new Error("could not read shader files", e); } program = GL20.glCreateProgram(); setObjectLabel(KHRDebug.GL_PROGRAM, program, name); GL20.glAttachShader(program, vertexShader); GL20.glAttachShader(program, fragmentShader); GL20.glBindAttribLocation(program, 0, "vertex"); GL20.glBindAttribLocation(program, 1, "texcoord"); GL20.glBindAttribLocation(program, 2, "color"); GL20.glLinkProgram(program); GL20.glValidateProgram(program); GL20.glDetachShader(program, vertexShader); GL20.glDetachShader(program, fragmentShader); GL20.glDeleteShader(vertexShader); GL20.glDeleteShader(fragmentShader); String log = GL20.glGetProgramInfoLog(program); if(debugOutput != null && !log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n"); if(GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == 0) { GL20.glDeleteProgram(program); throw new Error("Could not link " + name); } for(int i = 0;i != ufs.length;i++) { int uf = GL20.glGetUniformLocation(program, uniform_names[i]); ufs[i] = uf; } shaders.add(this); }
Example 8
Source File: ShaderArgs.java From FEMultiplayer with GNU General Public License v3.0 | 4 votes |
public void bindArgs(int program) { for(int i=0; i<args.length; i++) { int loc = GL20.glGetUniformLocation(program, "arg"+i); GL20.glUniform1f(loc, args[i]); } }
Example 9
Source File: ShaderHelper.java From OpenModsLib with MIT License | 4 votes |
@Override public int glGetUniformLocation(int program, String uniform) { return GL20.glGetUniformLocation(program, uniform); }