Java Code Examples for android.opengl.GLES20#glUniform3fv()

The following examples show how to use android.opengl.GLES20#glUniform3fv() . 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: ShaderTextureLights.java    From smartGL with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreRender(OpenGLRenderer renderer, RenderObject object, Face3D face3D) {

    float[] modelMatrix = object.getMatrix();
    GLES20.glUniformMatrix4fv(mModelMatrixId, 1, false, modelMatrix, 0);

    float[] lightDirection = renderer.getLightDirection();
    GLES20.glUniform3fv(mParallelLightDirectionId, 1, lightDirection, 0);

    float[] lightColor = renderer.getLightColor();
    GLES20.glUniform4fv(mParallelLightColorId, 1, lightColor, 0);

    float[] ambiant = renderer.getLightAmbiant();
    GLES20.glUniform4fv(mLightAmbiantId, 1, ambiant, 0);

    GLES20.glEnableVertexAttribArray(mNormalsId);
    NormalList normalList = face3D.getNormalList();
    FloatBuffer vertexBuffer = normalList.getFloatBuffer();
    vertexBuffer.position(0);
    GLES20.glVertexAttribPointer(mNormalsId, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
}
 
Example 2
Source File: ShaderColorLights.java    From smartGL with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreRender(OpenGLRenderer renderer, RenderObject object, Face3D face3D) {

    float[] modelMatrix = object.getMatrix();
    GLES20.glUniformMatrix4fv(mModelMatrixId, 1, false, modelMatrix, 0);

    float[] lightDirection = renderer.getLightDirection();
    GLES20.glUniform3fv(mParallelLightDirectionId, 1, lightDirection, 0);

    float[] lightColor = renderer.getLightColor();
    GLES20.glUniform4fv(mParallelLightColorId, 1, lightColor, 0);

    float[] ambiant = renderer.getLightAmbiant();
    GLES20.glUniform4fv(mLightAmbiantId, 1, ambiant, 0);

    GLES20.glEnableVertexAttribArray(mNormalsId);
    NormalList normalList = face3D.getNormalList();
    FloatBuffer vertexBuffer = normalList.getFloatBuffer();
    vertexBuffer.position(0);
    GLES20.glVertexAttribPointer(mNormalsId, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
}
 
Example 3
Source File: TreasureHuntActivity.java    From PanoramaGL with Apache License 2.0 6 votes vote down vote up
/**
 * Draw the floor.
 *
 * <p>This feeds in data for the floor into the shader. Note that this doesn't feed in data about
 * position of the light, so if we rewrite our code to draw the floor first, the lighting might
 * look strange.
 */
public void drawFloor() {
  GLES20.glUseProgram(floorProgram);

  // Set ModelView, MVP, position, normals, and color.
  GLES20.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0);
  GLES20.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0);
  GLES20.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0);
  GLES20.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0);
  GLES20.glVertexAttribPointer(
      floorPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, floorVertices);
  GLES20.glVertexAttribPointer(floorNormalParam, 3, GLES20.GL_FLOAT, false, 0, floorNormals);
  GLES20.glVertexAttribPointer(floorColorParam, 4, GLES20.GL_FLOAT, false, 0, floorColors);

  GLES20.glEnableVertexAttribArray(floorPositionParam);
  GLES20.glEnableVertexAttribArray(floorNormalParam);
  GLES20.glEnableVertexAttribArray(floorColorParam);

  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 24);

  checkGLError("drawing floor");
}
 
Example 4
Source File: VideoEncodeRender.java    From AudioVideoCodec with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame() {
    //清空颜色
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    //设置背景颜色
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    //使用程序
    GLES20.glUseProgram(program);

    GLES20.glUniform1i(changeType, type);
    GLES20.glUniform3fv(changeColor, 1, color, 0);

    //设置纹理
    //绑定渲染纹理  默认是第0个位置
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);

    GLES20.glEnableVertexAttribArray(avPosition);
    GLES20.glEnableVertexAttribArray(afPosition);

    //使用VBO设置纹理和顶点值
    useVboSetVertext();

    //绘制 GLES20.GL_TRIANGLE_STRIP:复用坐标
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(avPosition);
    GLES20.glDisableVertexAttribArray(afPosition);
    //解绑纹理
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    //开始绘制
    drawWater();
}
 
Example 5
Source File: TreasureHuntActivity.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the cube.
 *
 * <p>We've set all of our transformation matrices. Now we simply pass them into the shader.
 */
public void drawCube() {
  GLES20.glUseProgram(cubeProgram);

  GLES20.glUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0);

  // Set the Model in the shader, used to calculate lighting
  GLES20.glUniformMatrix4fv(cubeModelParam, 1, false, modelCube, 0);

  // Set the ModelView in the shader, used to calculate lighting
  GLES20.glUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0);

  // Set the position of the cube
  GLES20.glVertexAttribPointer(
      cubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, cubeVertices);

  // Set the ModelViewProjection matrix in the shader.
  GLES20.glUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0);

  // Set the normal positions of the cube, again for shading
  GLES20.glVertexAttribPointer(cubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, cubeNormals);
  GLES20.glVertexAttribPointer(cubeColorParam, 4, GLES20.GL_FLOAT, false, 0,
      isLookingAtObject() ? cubeFoundColors : cubeColors);

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(cubePositionParam);
  GLES20.glEnableVertexAttribArray(cubeNormalParam);
  GLES20.glEnableVertexAttribArray(cubeColorParam);

  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
  checkGLError("Drawing cube");
}
 
Example 6
Source File: ShaderToyAbsFilter.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(int textureId) {
    onPreDrawElements();
    int iResolutionLocation = GLES20.glGetUniformLocation(glSimpleProgram.getProgramId(), "iResolution");
    GLES20.glUniform3fv(iResolutionLocation, 1,
            FloatBuffer.wrap(new float[]{(float) surfaceWidth, (float) surfaceHeight, 1.0f}));

    float currentTime = ((float) (System.currentTimeMillis() - START_TIME)) / 1000.0f;
    setUniform1f(glSimpleProgram.getProgramId(), "iGlobalTime",currentTime);

    TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSimpleProgram.getTextureSamplerHandle(),0);
    GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
    plane.draw();
}
 
Example 7
Source File: GlVignetteFilter.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
@Override
public void onDraw() {
    GLES20.glUniform2f(getHandle("vignetteCenter"), vignetteCenterX, vignetteCenterY);
    GLES20.glUniform3fv(getHandle("vignetteColor"), 0, vignetteColor, 0);
    GLES20.glUniform1f(getHandle("vignetteStart"), vignetteStart);
    GLES20.glUniform1f(getHandle("vignetteEnd"), vignetteEnd);
}
 
Example 8
Source File: ShaderToyAbsFilter.java    From In77Camera with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(int textureId) {
    onPreDrawElements();
    int iResolutionLocation = GLES20.glGetUniformLocation(glSimpleProgram.getProgramId(), "iResolution");
    GLES20.glUniform3fv(iResolutionLocation, 1,
            FloatBuffer.wrap(new float[]{(float) surfaceWidth, (float) surfaceHeight, 1.0f}));

    float currentTime = ((float) (System.currentTimeMillis() - START_TIME)) / 1000.0f;
    setUniform1f(glSimpleProgram.getProgramId(), "iGlobalTime",currentTime);

    TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSimpleProgram.getTextureSamplerHandle(),0);
    GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
    plane.draw();
}
 
Example 9
Source File: GlVignetteFilter.java    From SimpleVideoEdit with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw() {
    GLES20.glUniform2f(getHandle("vignetteCenter"), vignetteCenterX, vignetteCenterY);
    GLES20.glUniform3fv(getHandle("vignetteColor"), 0, vignetteColor, 0);
    GLES20.glUniform1f(getHandle("vignetteStart"), vignetteStart);
    GLES20.glUniform1f(getHandle("vignetteEnd"), vignetteEnd);
}
 
Example 10
Source File: CameraRender.java    From AudioVideoCodec with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame() {
    //清空颜色
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    //设置背景颜色
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    //使用程序
    GLES20.glUseProgram(program);

    GLES20.glUniform1i(changeType, getType());
    GLES20.glUniform3fv(changeColor, 1, getColor(), 0);

    //设置纹理
    //绑定渲染纹理  默认是第0个位置
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fboTextureId);

    GLES20.glEnableVertexAttribArray(avPosition);
    GLES20.glEnableVertexAttribArray(afPosition);

    //使用VBO设置纹理和顶点值
    useVboSetVertext();

    //绘制 GLES20.GL_TRIANGLE_STRIP:复用坐标
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(avPosition);
    GLES20.glDisableVertexAttribArray(afPosition);
    //解绑纹理
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    //开始绘制
    drawWater();
}
 
Example 11
Source File: GlMonochromeFilter.java    From CameraRecorder-android with MIT License 4 votes vote down vote up
@Override
public void onDraw() {
    GLES20.glUniform1f(getHandle("intensity"), intensity);
    GLES20.glUniform3fv(getHandle("filterColor"), 0, filterColor, 0);
}
 
Example 12
Source File: ShaderProgram.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
public void setFloatVec3(final int location, final float[] arrayValue) {
    GLES20.glUniform3fv(location, 1, FloatBuffer.wrap(arrayValue));
}
 
Example 13
Source File: GLScene.java    From MusicVisualization with Apache License 2.0 4 votes vote down vote up
protected void runShandertoyProgram(
        int program, FloatBuffer vertex, FloatBuffer textureCoord,
        int[] iResolution, int[] iChannels, int[][] iChannelResolutions) {

    GLES20.glUseProgram(program);

    int iResolutionLocation = GLES20.glGetUniformLocation(program, "iResolution");
    GLES20.glUniform3fv(iResolutionLocation, 1,
            FloatBuffer.wrap(new float[]{(float) iResolution[0], (float) iResolution[1], 1.0f}));

    float time = ((float) (System.currentTimeMillis() - mStartTime)) / 1000.0f;
    int iGlobalTimeLocation = GLES20.glGetUniformLocation(program, "iTime");
    GLES20.glUniform1f(iGlobalTimeLocation, time);

    int iFrameLocation = GLES20.glGetUniformLocation(program, "iFrame");
    GLES20.glUniform1i(iFrameLocation, iFrame);

    int vPositionLocation = GLES20.glGetAttribLocation(program, "vPosition");
    GLES20.glEnableVertexAttribArray(vPositionLocation);
    GLES20.glVertexAttribPointer(vPositionLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, vertex);

    int vTexCoordLocation = GLES20.glGetAttribLocation(program, "vTexCoord");
    GLES20.glEnableVertexAttribArray(vTexCoordLocation);
    GLES20.glVertexAttribPointer(vTexCoordLocation, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoord);

    for (int i = 0; i < iChannels.length; i++) {
        int sTextureLocation = GLES20.glGetUniformLocation(program, "iChannel" + i);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, iChannels[i]);
        GLES20.glUniform1i(sTextureLocation, i);
    }

    float _iChannelResolutions[] = new float[iChannelResolutions.length * 3];
    for (int i = 0; i < iChannelResolutions.length; i++) {
        _iChannelResolutions[i * 3] = iChannelResolutions[i][0];
        _iChannelResolutions[i * 3 + 1] = iChannelResolutions[i][1];
        _iChannelResolutions[i * 3 + 2] = 1.0f;
    }

    int iChannelResolutionLocation = GLES20.glGetUniformLocation(program, "iChannelResolution");
    GLES20.glUniform3fv(iChannelResolutionLocation,
            _iChannelResolutions.length, FloatBuffer.wrap(_iChannelResolutions));

    // Draw
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
 
Example 14
Source File: GlMonochromeFilter.java    From SimpleVideoEdit with Apache License 2.0 4 votes vote down vote up
@Override
public void onDraw() {
    GLES20.glUniform1f(getHandle("intensity"), intensity);
    GLES20.glUniform3fv(getHandle("filterColor"), 0, filterColor, 0);
}
 
Example 15
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void uniform3fv(int location, int count, FloatBuffer v) {
    GLES20.glUniform3fv(location, count, v);

}
 
Example 16
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void uniform3fv(int location, int count, float[] v, int offset) {
    GLES20.glUniform3fv(location, count, v, offset);
}
 
Example 17
Source File: DrawerImpl.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setCameraPos(float[] cameraPosInWorldSpace) {
    int mLightPosHandle = GLES20.glGetUniformLocation(mProgram, "u_cameraPos");
    // Pass in the light position in eye space.
    GLES20.glUniform3fv(mLightPosHandle, 0, cameraPosInWorldSpace, 0);
}
 
Example 18
Source File: GLES20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void drawUnified2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, boolean image, boolean shadow, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) {
	useProgram(prog_unified);
	bindTexture(texture);

	if(image) {
		float r, g, b, a;
		if (color != null) {
			r = color.red * intensity;
			g = color.green * intensity;
			b = color.blue * intensity;
			a = color.alpha;
		} else {
			r = g = b = intensity;
			a = 1;
		}

		if(ulr != r || ulg != g || ulb != b || ula != a) {
			ulr = r;
			ulg = g;
			ulb = b;
			ula = a;
			GLES20.glUniform4f(prog_unified.ufs[COLOR], r, g, b, a);
		}
	}

	if(ulim != image || ulsh != shadow || uli != intensity) {
		GLES20.glUniform3f(prog_unified.ufs[UNI_INFO], image?1:0, shadow?1:0, intensity);
		ulim = image;
		ulsh = shadow;
		uli = intensity;
	}

	GLES20.glUniform3fv(lastProgram.ufs[TRANS], 2, new float[] {x, y, z, sx, sy, sz}, 0);

	if(gles3) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GLES20.glDrawArrays(primitive, offset*vertices, vertices);
}
 
Example 19
Source File: GLModel.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context, Data data)
{
  ShaderModel shader = (ShaderModel) Shader.getCurrent();
  Light.Data light = context.getLight();

  // build PVM matrix
  Matrix.multiplyMM(modelProjectionViewMatrix, 0, context.getProjectionViewMatrix(), 0, modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send uniform data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix4fv(shader.uniformMatrixProjectionHandle, 1, false, modelProjectionViewMatrix, 0);
  GLES20.glUniformMatrix3fv(shader.uniformNormalMatrix, 1, false, modelNormalMatrix, 0);
  GLES20.glUniformMatrix4fv(shader.uniformMatrixHandle, 1, false, modelMatrix, 0);
  GLES20.glUniform3fv(shader.uniformLightVectorHandle, 1, light.Position.getRaw(), 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, data.redCoeff, data.greenCoeff, data.blueCoeff, 1.0f);

  // bind data buffer
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  // set offsets to arrays for buffer
  GLES20.glVertexAttribPointer(shader.attributePositionHandle, 3, GLES20.GL_FLOAT, false, 32, 0);
  GLES20.glVertexAttribPointer(shader.attributeNormalHandle, 3, GLES20.GL_FLOAT, false, 32, 12);
  GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 32, 24);

  // enable attribute arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeNormalHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable attribute arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeNormalHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);
}
 
Example 20
Source File: ShaderRenderer.java    From ShaderEditor with MIT License 4 votes vote down vote up
private void setRotationMatrix() {
	boolean haveInclination = false;
	if (gravityListener != null && magneticFieldListener != null &&
			SensorManager.getRotationMatrix(
					rotationMatrix,
					inclinationMatrix,
					gravityValues,
					magneticFieldListener.filtered)) {
		haveInclination = true;
	} else if (rotationVectorListener != null) {
		SensorManager.getRotationMatrixFromVector(
				rotationMatrix,
				rotationVectorListener.values);
	} else {
		return;
	}
	if (deviceRotation != 0) {
		int x = SensorManager.AXIS_Y;
		int y = SensorManager.AXIS_MINUS_X;
		switch (deviceRotation) {
			default:
				break;
			case 270:
				x = SensorManager.AXIS_MINUS_Y;
				y = SensorManager.AXIS_X;
				break;
		}
		SensorManager.remapCoordinateSystem(
				rotationMatrix,
				x,
				y,
				rotationMatrix);
	}
	if (rotationMatrixLoc > -1) {
		GLES20.glUniformMatrix3fv(rotationMatrixLoc, 1, true,
				rotationMatrix, 0);
	}
	if (orientationLoc > -1) {
		SensorManager.getOrientation(rotationMatrix, orientation);
		GLES20.glUniform3fv(orientationLoc, 1, orientation, 0);
	}
	if (inclinationMatrixLoc > -1 && haveInclination) {
		GLES20.glUniformMatrix3fv(inclinationMatrixLoc, 1, true,
				inclinationMatrix, 0);
	}
	if (inclinationLoc > -1 && haveInclination) {
		GLES20.glUniform1f(inclinationLoc,
				SensorManager.getInclination(inclinationMatrix));
	}
}