Java Code Examples for com.jogamp.opengl.GL2GL3#glGetUniformLocation()

The following examples show how to use com.jogamp.opengl.GL2GL3#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: Polygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
public static void init(Renderer r, GL2GL3 gl) {
	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	_vertBuffer = is[0];

	Shader s = r.getShader(ShaderHandle.DEBUG);
	_progHandle = s.getProgramHandle();
	gl.glUseProgram(_progHandle);

	_modelViewMatVar = gl.glGetUniformLocation(_progHandle, "modelViewMat");
	_projMatVar = gl.glGetUniformLocation(_progHandle, "projMat");
	_colorVar = gl.glGetUniformLocation(_progHandle, "color");

	_cVar = gl.glGetUniformLocation(_progHandle, "C");
	_fcVar = gl.glGetUniformLocation(_progHandle, "FC");

	_posVar = gl.glGetAttribLocation(_progHandle, "position");

	_hasInitialized = true;
}
 
Example 2
Source File: OverlayPolygon.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private static void initStaticData(Renderer r) {
	GL2GL3 gl = r.getGL();

	// Initialize the shader variables
	progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	glBuff = is[0];

	hasTexVar = gl.glGetUniformLocation(progHandle, "useTex");
	sizeVar = gl.glGetUniformLocation(progHandle, "size");
	offsetVar = gl.glGetUniformLocation(progHandle, "offset");
	colorVar = gl.glGetUniformLocation(progHandle, "color");

	posVar = gl.glGetAttribLocation(progHandle, "position");
	staticInit = true;
}
 
Example 3
Source File: OverlayLine.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private static void initStaticData(Renderer r) {
	GL2GL3 gl = r.getGL();

	// Initialize the shader variables
	progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	lineGLBuff = is[0];

	hasTexVar = gl.glGetUniformLocation(progHandle, "useTex");
	sizeVar = gl.glGetUniformLocation(progHandle, "size");
	offsetVar = gl.glGetUniformLocation(progHandle, "offset");
	colorVar = gl.glGetUniformLocation(progHandle, "color");

	posVar = gl.glGetAttribLocation(progHandle, "position");
	staticInit = true;
}
 
Example 4
Source File: Skybox.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public static void loadGPUAssets(Renderer r) {

		GL2GL3 gl = r.getGL();

		int[] buffs = new int[1];
		gl.glGenBuffers(1, buffs, 0);
		vertBuff = buffs[0];

		progHandle = r.getShader(Renderer.ShaderHandle.SKYBOX).getProgramHandle();

		projMatVar = gl.glGetUniformLocation(progHandle, "projMat");
		invViewMatVar = gl.glGetUniformLocation(progHandle, "invViewMat");
		texVar = gl.glGetUniformLocation(progHandle, "tex");

		FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates
		verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f);

		verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f);
		verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f);
		verts.put(-0.5f); verts.put( 0.5f); verts.put(-0.5f);

		verts.flip();
		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff);
		gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW);

		gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

		isLoaded = true;
	}
 
Example 5
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private static void initBSInfo(Renderer r, GL2GL3 gl) {
	BatchShaderInfo si = bsInfo;

	si.progHandle = r.getShader(ShaderHandle.MESH_BATCH).getProgramHandle();
	int ph = bsInfo.progHandle;

	gl.glUseProgram(ph);

	si.instSpaceMatVar = gl.glGetAttribLocation(ph, "instSpaceMat");
	si.instSpaceNorMatVar = gl.glGetAttribLocation(ph, "instSpaceNorMat");

	// Bind the shader variables
	si.modelViewMatVar = gl.glGetUniformLocation(ph, "modelViewMat");
	si.projMatVar = gl.glGetUniformLocation(ph, "projMat");
	si.normalMatVar = gl.glGetUniformLocation(ph, "normalMat");

	si.posVar = gl.glGetAttribLocation(ph, "position");
	si.norVar = gl.glGetAttribLocation(ph, "normal");
	si.texCoordVar = gl.glGetAttribLocation(ph, "texCoord");

	si.diffTexVar = gl.glGetUniformLocation(ph, "diffTexs");

	si.diffuseColorVar = gl.glGetAttribLocation(ph, "diffuseColorV");
	si.diffTexIndexVar = gl.glGetAttribLocation(ph, "diffTexIndexV");
	si.ambientColorVar = gl.glGetAttribLocation(ph, "ambientColorV");
	si.specColorVar = gl.glGetAttribLocation(ph, "specColorV");
	si.shininessVar = gl.glGetAttribLocation(ph, "shininessV");

	si.lightDirVar = gl.glGetUniformLocation(ph, "lightDir");
	si.lightIntVar = gl.glGetUniformLocation(ph, "lightIntensity");
	si.numLightsVar = gl.glGetUniformLocation(ph, "numLights");

	si.cVar = gl.glGetUniformLocation(ph, "C");
	si.fcVar = gl.glGetUniformLocation(ph, "FC");

}
 
Example 6
Source File: MeshProto.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void loadGPUSubLine(GL2GL3 gl, Renderer renderer, MeshData.SubLineData data) {

	Shader s = renderer.getShader(Renderer.ShaderHandle.DEBUG);

	assert (s.isGood());

	SubLine sub = new SubLine();
	sub._progHandle = s.getProgramHandle();

	int[] is = new int[1];
	gl.glGenBuffers(1, is, 0);
	sub._vertexBuffer = is[0];

	sub._numVerts = data.verts.size();

	sub._hull = data.hull;

	// Init vertices
	FloatBuffer fb = FloatBuffer.allocate(data.verts.size() * 3); //
	for (Vec3d v : data.verts) {
		RenderUtils.putPointXYZ(fb, v);
	}
	fb.flip();

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, sub._vertexBuffer);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, sub._numVerts * 3 * 4, fb, GL2GL3.GL_STATIC_DRAW);

	// Bind the shader variables
	sub._modelViewMatVar = gl.glGetUniformLocation(sub._progHandle, "modelViewMat");
	sub._projMatVar = gl.glGetUniformLocation(sub._progHandle, "projMat");

	sub._diffuseColor = new Color4d(data.diffuseColor);
	sub._colorVar = gl.glGetUniformLocation(sub._progHandle, "color");

	sub._cVar = gl.glGetUniformLocation(sub._progHandle, "C");
	sub._fcVar = gl.glGetUniformLocation(sub._progHandle, "FC");

	_subLines.add(sub);
}
 
Example 7
Source File: TextureView.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private static void initStaticBuffers(Renderer r) {
	GL2GL3 gl = r.getGL();

	int[] buffs = new int[3];
	gl.glGenBuffers(3, buffs, 0);
	vertBuff = buffs[0];
	texCoordBuff = buffs[1];
	normalBuff = buffs[2];

	FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates
	verts.put(-0.5f); verts.put(-0.5f); verts.put(0.0f);
	verts.put( 0.5f); verts.put(-0.5f); verts.put(0.0f);
	verts.put( 0.5f); verts.put( 0.5f); verts.put(0.0f);

	verts.put(-0.5f); verts.put(-0.5f); verts.put(0.0f);
	verts.put( 0.5f); verts.put( 0.5f); verts.put(0.0f);
	verts.put(-0.5f); verts.put( 0.5f); verts.put(0.0f);

	verts.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW);

	FloatBuffer texCoords = FloatBuffer.allocate(6*2); // 2 triangles * 2 coordinates

	texCoords.put(0.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(1.0f);

	texCoords.put(0.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(1.0f);
	texCoords.put(0.0f); texCoords.put(1.0f);

	texCoords.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*2*4, texCoords, GL2GL3.GL_STATIC_DRAW);

	FloatBuffer normals = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates
	for (int i = 0; i < 6; ++i) {
		normals.put(0.0f); normals.put(0.0f); normals.put(1.0f);
	}

	normals.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, normalBuff);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, normals, GL2GL3.GL_STATIC_DRAW);

	// Initialize the shader variables
	progHandle = r.getMeshShader(Renderer.DIFF_TEX_FLAG).getProgramHandle();

	modelViewMatVar = gl.glGetUniformLocation(progHandle, "modelViewMat");
	projMatVar = gl.glGetUniformLocation(progHandle, "projMat");
	normalMatVar = gl.glGetUniformLocation(progHandle, "normalMat");
	bindSpaceMatVar = gl.glGetUniformLocation(progHandle, "bindSpaceMat");
	bindSpaceNorMatVar = gl.glGetUniformLocation(progHandle, "bindSpaceNorMat");
	texVar = gl.glGetUniformLocation(progHandle, "diffuseTex");

	lightDirVar = gl.glGetUniformLocation(progHandle, "lightDir");
	lightIntVar = gl.glGetUniformLocation(progHandle, "lightIntensity");
	numLightsVar = gl.glGetUniformLocation(progHandle, "numLights");

	specColorVar = gl.glGetUniformLocation(progHandle, "specColor");
	ambientColorVar = gl.glGetUniformLocation(progHandle, "ambientColor");
	shininessVar = gl.glGetUniformLocation(progHandle, "shininess");

	cVar = gl.glGetUniformLocation(progHandle, "C");
	fcVar = gl.glGetUniformLocation(progHandle, "FC");

	lightDir[0] = 0;
	lightDir[1] = 0;
	lightDir[2] = -1;

	lightInt[0] = 1;

	staticInit = true;
}
 
Example 8
Source File: OverlayTexture.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private static void initStaticBuffers(Renderer r) {
	GL2GL3 gl = r.getGL();

	int[] buffs = new int[2];
	gl.glGenBuffers(2, buffs, 0);
	vertBuff = buffs[0];
	texCoordBuff = buffs[1];

	FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates
	verts.put(0.0f); verts.put(0.0f); verts.put(0.0f);
	verts.put(1.0f); verts.put(0.0f); verts.put(0.0f);
	verts.put(1.0f); verts.put(1.0f); verts.put(0.0f);

	verts.put(0.0f); verts.put(0.0f); verts.put(0.0f);
	verts.put(1.0f); verts.put(1.0f); verts.put(0.0f);
	verts.put(0.0f); verts.put(1.0f); verts.put(0.0f);

	verts.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW);

	FloatBuffer texCoords = FloatBuffer.allocate(6*2); // 2 triangles * 2 coordinates

	texCoords.put(0.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(1.0f);

	texCoords.put(0.0f); texCoords.put(0.0f);
	texCoords.put(1.0f); texCoords.put(1.0f);
	texCoords.put(0.0f); texCoords.put(1.0f);

	texCoords.flip();
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*2*4, texCoords, GL2GL3.GL_STATIC_DRAW);

	// Initialize the shader variables
	progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle();

	texVar = gl.glGetUniformLocation(progHandle, "tex");
	hasTexVar = gl.glGetUniformLocation(progHandle, "useTex");
	sizeVar = gl.glGetUniformLocation(progHandle, "size");
	offsetVar = gl.glGetUniformLocation(progHandle, "offset");

	staticInit = true;
}
 
Example 9
Source File: MeshProto.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private void renderStaticLines(int contextID, Renderer renderer, Mat4d modelViewMat, Camera cam) {

	if (_lineBatches.size() == 0) {
		return;
	}

	GL2GL3 gl = renderer.getGL();
	GL4 gl4 = renderer.getGL4();

	if (!_lineVAOs.containsKey(contextID)) {
		setupVAOForStaticLines(contextID, renderer);
	}

	int vao = _lineVAOs.get(contextID);
	gl.glBindVertexArray(vao);

	Shader s = renderer.getShader(ShaderHandle.DEBUG_BATCH);
	int progHandle = s.getProgramHandle();
	gl.glUseProgram(progHandle);

	Mat4d projMat = cam.getProjMat4d();

	int modelViewMatVar = gl.glGetUniformLocation(progHandle, "modelViewMat");
	int projMatVar = gl.glGetUniformLocation(progHandle, "projMat");

	int cVar = gl.glGetUniformLocation(progHandle, "C");
	int fcVar = gl.glGetUniformLocation(progHandle, "FC");

	gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0);
	gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0);

	gl.glUniform1f(cVar, Camera.C);
	gl.glUniform1f(fcVar, Camera.FC);

	gl.glLineWidth(1);

	// Actually draw it
	gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, lineIndirectBuffer);
	gl4.glMultiDrawArraysIndirect(GL2GL3.GL_LINES, 0, _lineBatches.size(), 0);

	//gl.glDrawArrays(GL2GL3.GL_LINES, 0, sub._numVerts);

	gl.glBindVertexArray(0);
}
 
Example 10
Source File: MeshProto.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
public static void init(Renderer r, GL2GL3 gl) {
	for (int i = 0; i < Renderer.NUM_MESH_SHADERS; ++i) {
		ShaderInfo si = new ShaderInfo();
		sInfos[i] = si;

		si.meshProgHandle = r.getMeshShader(i).getProgramHandle();

		gl.glUseProgram(si.meshProgHandle);

		// Bind the shader variables
		si.modelViewMatVar = gl.glGetUniformLocation(si.meshProgHandle, "modelViewMat");
		si.projMatVar = gl.glGetUniformLocation(si.meshProgHandle, "projMat");
		si.normalMatVar = gl.glGetUniformLocation(si.meshProgHandle, "normalMat");
		si.diffuseColorVar = gl.glGetUniformLocation(si.meshProgHandle, "diffuseColor");
		si.ambientColorVar = gl.glGetUniformLocation(si.meshProgHandle, "ambientColor");
		si.specColorVar = gl.glGetUniformLocation(si.meshProgHandle, "specColor");
		si.shininessVar = gl.glGetUniformLocation(si.meshProgHandle, "shininess");
		si.texVar = gl.glGetUniformLocation(si.meshProgHandle, "diffuseTex");

		si.lightDirVar = gl.glGetUniformLocation(si.meshProgHandle, "lightDir");
		si.lightIntVar = gl.glGetUniformLocation(si.meshProgHandle, "lightIntensity");
		si.numLightsVar = gl.glGetUniformLocation(si.meshProgHandle, "numLights");

		si.cVar = gl.glGetUniformLocation(si.meshProgHandle, "C");
		si.fcVar = gl.glGetUniformLocation(si.meshProgHandle, "FC");

		if ((i & Renderer.STATIC_BATCH_FLAG) == 0) {
			// We do not use the uniform bind space variables when batch rendering
			si.bindSpaceMatVar = gl.glGetUniformLocation(si.meshProgHandle, "bindSpaceMat");
			si.bindSpaceNorMatVar = gl.glGetUniformLocation(si.meshProgHandle, "bindSpaceNorMat");
		}

	}

	numLights = 2;


	lightsDir[0] = new Vec4d(-0.3, -0.2, -0.5, 0.0);
	lightsDir[1] = new Vec4d( 0.5, 1.0, -0.1, 0.0);

	lightsDir[0].normalize3();
	lightsDir[1].normalize3();

	lightsInt[0] = 1f;
	lightsInt[1] = 0.5f;

	lightsDirScratch[0] = new Vec4d();
	lightsDirScratch[1] = new Vec4d();

	if (r.isIndirectSupported()) {
		initBSInfo(r, gl);
	}
}
 
Example 11
Source File: DebugUtils.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the GL assets needed, this should be called with the shared GL context
 * @param gl
 */
public static void init(Renderer r, GL2GL3 gl) {
	int[] is = new int[3];
	gl.glGenBuffers(3, is, 0);
	_aabbVertBuffer = is[0];
	_boxVertBuffer = is[1];
	_lineVertBuffer = is[2];

	Shader s = r.getShader(ShaderHandle.DEBUG);
	_debugProgHandle = s.getProgramHandle();
	gl.glUseProgram(_debugProgHandle);

	_modelViewMatVar = gl.glGetUniformLocation(_debugProgHandle, "modelViewMat");
	_projMatVar = gl.glGetUniformLocation(_debugProgHandle, "projMat");
	_colorVar = gl.glGetUniformLocation(_debugProgHandle, "color");

	_posVar = gl.glGetAttribLocation(_debugProgHandle, "position");

	_cVar = gl.glGetAttribLocation(_debugProgHandle, "C");
	_fcVar = gl.glGetAttribLocation(_debugProgHandle, "FC");

	// Build up a buffer of vertices for lines in a box
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _aabbVertBuffer);

	FloatBuffer fb = FloatBuffer.allocate(3 * 2 * 12); // 12 line segments
	// Top lines
	app( 1,  1,  1, fb);
	app( 1, -1,  1, fb);

	app( 1, -1,  1, fb);
	app(-1, -1,  1, fb);

	app(-1, -1,  1, fb);
	app(-1,  1,  1, fb);

	app(-1,  1,  1, fb);
	app( 1,  1,  1, fb);

	// Bottom lines
	app( 1,  1, -1, fb);
	app( 1, -1, -1, fb);

	app( 1, -1, -1, fb);
	app(-1, -1, -1, fb);

	app(-1, -1, -1, fb);
	app(-1,  1, -1, fb);

	app(-1,  1, -1, fb);
	app( 1,  1, -1, fb);

	// Side lines
	app( 1,  1,  1, fb);
	app( 1,  1, -1, fb);

	app(-1,  1,  1, fb);
	app(-1,  1, -1, fb);

	app( 1, -1,  1, fb);
	app( 1, -1, -1, fb);

	app(-1, -1,  1, fb);
	app(-1, -1, -1, fb);

	fb.flip();

	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 3 * 2 * 12 * 4, fb, GL2GL3.GL_STATIC_DRAW);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	// Create a buffer for drawing rectangles
	// Build up a buffer of vertices for lines in a box
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _boxVertBuffer);

	fb = FloatBuffer.allocate(3 * 2 * 4); // 4 line segments

	// lines
	app( 0.5f,  0.5f,  0, fb);
	app( 0.5f, -0.5f,  0, fb);

	app( 0.5f, -0.5f,  0, fb);
	app(-0.5f, -0.5f,  0, fb);

	app(-0.5f, -0.5f,  0, fb);
	app(-0.5f,  0.5f,  0, fb);

	app(-0.5f,  0.5f,  0, fb);
	app( 0.5f,  0.5f,  0, fb);

	fb.flip();

	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 3 * 2 * 4 * 4, fb, GL2GL3.GL_STATIC_DRAW);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

}
 
Example 12
Source File: BillboardString.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
/**
 * Note: render() and renderForView() are mutually non-reentrant due to shared temporaries. This should be fine
 * because neither should ever be called by any thread other than the render thread.
 */
@Override
public void render(int contextID, Renderer renderer, double windowWidth,
		double windowHeight, Camera cam, Ray pickRay) {

	GL2GL3 gl = renderer.getGL();

	if (!VAOMap.containsKey(contextID)) {
		setupVAO(contextID, renderer);
	}

	int vao = VAOMap.get(contextID);
	gl.glBindVertexArray(vao);

	// Render the string
	Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT);

	s.useShader(gl);
	int prog = s.getProgramHandle();

	// Work out the billboard position
	cam.getViewMat4d(tempViewMat);
	// Build up the projection*view matrix
	tempViewMat.mult4(cam.getProjMat4d(), tempViewMat);

	tempPos.x = _pos.x;
	tempPos.y = _pos.y;
	tempPos.z = _pos.z;
	tempPos.w = 1.0;

	tempPos.mult4(tempViewMat, tempPos);
	tempPos.x /= tempPos.w;
	tempPos.y /= tempPos.w;
	// TempPos x and y are now in normalized coordinate space (after the projection)

	int colorVar = gl.glGetUniformLocation(prog, "color");
	gl.glUniform4fv(colorVar, 1, _color, 0);

	int posVar = gl.glGetAttribLocation(prog, "position");
	gl.glEnableVertexAttribArray(posVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl));
	gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	int offsetVar = gl.glGetUniformLocation(prog, "offset");

	float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight()));
	float scaleX = scaleY * (float)(windowHeight/windowWidth);

	int scaleVar = gl.glGetUniformLocation(prog, "scale");
	gl.glUniform2f(scaleVar, scaleX, scaleY);

	float offsetX = (float)tempPos.x;
	float offsetY = (float)tempPos.y;

	offsetX += _xOffset*2.0/windowWidth;
	offsetY += _yOffset*2.0/windowHeight;

	gl.glDisable(GL2GL3.GL_CULL_FACE);

	for (int cp : RenderUtils.stringToCodePoints(_contents)) {
		TessChar tc = _font.getTessChar(cp);
		if (tc == null) {
			assert(false);
			continue;
		}

		gl.glUniform2f(offsetVar, offsetX, offsetY);

		gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts());

		offsetX += tc.getAdvance()*scaleX;
	}

	gl.glEnable(GL2GL3.GL_CULL_FACE);

}
 
Example 13
Source File: TessString.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
@Override
public void render(int contextID, Renderer renderer, Camera cam, Ray pickRay) {
	GL2GL3 gl = renderer.getGL();

	if (!VAOMap.containsKey(contextID)) {
		setupVAO(contextID, renderer);
	}

	int vao = VAOMap.get(contextID);
	gl.glBindVertexArray(vao);

	// Render the string
	Shader s = renderer.getShader(Renderer.ShaderHandle.FONT);

	s.useShader(gl);
	int prog = s.getProgramHandle();

	// Setup uniforms for this object
	Mat4d modelViewProjMat = new Mat4d();
	cam.getViewMat4d(modelViewProjMat);
	modelViewProjMat.mult4(_trans);

	Mat4d projMat = cam.getProjMat4d();
	modelViewProjMat.mult4(projMat, modelViewProjMat);

	int modelViewProjMatVar = gl.glGetUniformLocation(prog, "modelViewProjMat");
	gl.glUniformMatrix4fv(modelViewProjMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewProjMat), 0);

	int colorVar = gl.glGetUniformLocation(prog, "color");
	gl.glUniform4fv(colorVar, 1, _color, 0);

	int cVar = gl.glGetUniformLocation(prog, "C");
	gl.glUniform1f(cVar, Camera.C);

	int fcVar = gl.glGetUniformLocation(prog, "FC");
	gl.glUniform1f(fcVar, Camera.FC);

	int advanceVar = gl.glGetUniformLocation(prog, "advance");

	int posVar = gl.glGetAttribLocation(prog, "position");
	gl.glEnableVertexAttribArray(posVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl));
	gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);


	// Send out one draw call per character
	float advance = 0;

	gl.glDisable(GL2GL3.GL_CULL_FACE);

	for (int i = 0; i < _contents.length; ++i) {

		gl.glUniform1f(advanceVar, advance);

		gl.glDrawArrays(GL2GL3.GL_TRIANGLES, starts[i], numVerts[i]);

		advance += advances[i];
	}
	gl.glEnable(GL2GL3.GL_CULL_FACE);

	// Cleanup
	gl.glDisableVertexAttribArray(posVar);
}
 
Example 14
Source File: OverlayString.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
@Override
public void render(int contextID, Renderer renderer,
	double windowWidth, double windowHeight, Camera cam, Ray pickRay) {


	Vec3d renderedSize = _font.getStringSize(_height, _contents);
	double x = _x;
	double y = _y;
	if (_alignRight) {
		x = windowWidth - _x - renderedSize.x;
	}
	if (!_alignBottom) {
		y = windowHeight - _y - renderedSize.y;
	}


	GL2GL3 gl = renderer.getGL();

	if (!VAOMap.containsKey(contextID)) {
		setupVAO(contextID, renderer);
	}

	int vao = VAOMap.get(contextID);
	gl.glBindVertexArray(vao);

	// Render the string
	Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT);

	s.useShader(gl);
	int prog = s.getProgramHandle();

	int colorVar = gl.glGetUniformLocation(prog, "color");
	gl.glUniform4fv(colorVar, 1, _color, 0);

	int posVar = gl.glGetAttribLocation(prog, "position");
	gl.glEnableVertexAttribArray(posVar);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl));
	gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	int offsetVar = gl.glGetUniformLocation(prog, "offset");

	float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight()));
	float scaleX = scaleY * (float)(windowHeight/windowWidth);

	int scaleVar = gl.glGetUniformLocation(prog, "scale");
	gl.glUniform2f(scaleVar, scaleX, scaleY);

	float offsetX = (float)(2*x/windowWidth - 1);
	float offsetY = (float)(2*y/windowHeight - 1);

	gl.glDisable(GL2GL3.GL_CULL_FACE);

	for (int cp : RenderUtils.stringToCodePoints(_contents)) {
		TessChar tc = _font.getTessChar(cp);
		if (tc == null) {
			assert(false);
			continue;
		}

		gl.glUniform2f(offsetVar, offsetX, offsetY);

		gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts());

		offsetX += tc.getAdvance()*scaleX;
	}

	gl.glEnable(GL2GL3.GL_CULL_FACE);
}
 
Example 15
Source File: HullProto.java    From jaamsim with Apache License 2.0 2 votes vote down vote up
public void render(int contextID, Renderer renderer,
           Mat4d modelViewMat,
           Camera cam) {

	GL2GL3 gl = renderer.getGL();

	Shader s = renderer.getShader(Renderer.ShaderHandle.HULL);

	int progHandle = s.getProgramHandle();
	gl.glUseProgram(progHandle);

	int modelViewMatVar = gl.glGetUniformLocation(progHandle, "modelViewMat");
	int projMatVar = gl.glGetUniformLocation(progHandle, "projMat");

	int cVar = gl.glGetUniformLocation(progHandle, "C");
	int fcVar = gl.glGetUniformLocation(progHandle, "FC");

	int[] is = new int[2];
	gl.glGenBuffers(2, is, 0);
	int vertexBuffer = is[0];
	int indexBuffer = is[1];

	List<Vec3d> verts = _hull.getVertices();
	// Generate the vertex buffer
	FloatBuffer fb = FloatBuffer.allocate(verts.size() * 3); //
	for (Vec3d v : verts) {
		RenderUtils.putPointXYZ(fb, v);
	}
	fb.flip();

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertexBuffer);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, verts.size() * 3 * 4, fb, GL2GL3.GL_STATIC_DRAW);

	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);

	// Generate the index buffer
	List<ConvexHull.HullFace> faces = _hull.getFaces();

	int numIndices = faces.size() * 3;

	IntBuffer ib = IntBuffer.allocate(faces.size() * 3); //
	for (ConvexHull.HullFace f : faces) {
		ib.put(f.indices, 0 ,3);
	}

	ib.flip();

	gl.glBindBuffer(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
	gl.glBufferData(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, faces.size() * 3 * 4, ib, GL2GL3.GL_STATIC_DRAW);

	gl.glBindBuffer(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, 0);

	if (!_vaoMap.containsKey(contextID)) {
		setupVAO(contextID, renderer, progHandle, vertexBuffer, indexBuffer);
	}

	int vao = _vaoMap.get(contextID);
	gl.glBindVertexArray(vao);

	gl.glUseProgram(progHandle);

	// Setup uniforms for this object
	Mat4d projMat = cam.getProjMat4d();

	gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0);
	gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0);

	gl.glUniform1f(cVar, Camera.C);
	gl.glUniform1f(fcVar, Camera.FC);

	// Actually draw it

	gl.glEnable(GL2GL3.GL_BLEND);
	gl.glEnable(GL2GL3.GL_CULL_FACE);
	gl.glCullFace(GL2GL3.GL_BACK);

	gl.glBlendFunc(GL2GL3.GL_ONE, GL2GL3.GL_ONE_MINUS_SRC_ALPHA);
	gl.glBlendEquation(GL2GL3.GL_FUNC_ADD);

	gl.glDisable(GL2GL3.GL_DEPTH_TEST);

	//gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);

	gl.glDrawElements(GL2GL3.GL_TRIANGLES, numIndices, GL2GL3.GL_UNSIGNED_INT, 0);

	//gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);

	gl.glEnable(GL2GL3.GL_DEPTH_TEST);

	gl.glDisable(GL2GL3.GL_CULL_FACE);
	gl.glCullFace(GL2GL3.GL_BACK);

	gl.glDisable(GL2GL3.GL_BLEND);

	gl.glBindVertexArray(0);

	gl.glDeleteBuffers(2, is, 0);

}