本文整理汇总了Java中android.opengl.GLES20.glGetAttribLocation方法的典型用法代码示例。如果您正苦于以下问题:Java GLES20.glGetAttribLocation方法的具体用法?Java GLES20.glGetAttribLocation怎么用?Java GLES20.glGetAttribLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.opengl.GLES20
的用法示例。
在下文中一共展示了GLES20.glGetAttribLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initShaders
import android.opengl.GLES20; //导入方法依赖的package包/类
private void initShaders() {
String strGLVersion = GLES20.glGetString(GLES20.GL_VERSION);
if (strGLVersion != null)
Log.i(LOGTAG, "OpenGL ES version: " + strGLVersion);
GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
progOES = loadShader(vss, fssOES);
vPosOES = GLES20.glGetAttribLocation(progOES, "vPosition");
vTCOES = GLES20.glGetAttribLocation(progOES, "vTexCoord");
GLES20.glEnableVertexAttribArray(vPosOES);
GLES20.glEnableVertexAttribArray(vTCOES);
prog2D = loadShader(vss, fss2D);
vPos2D = GLES20.glGetAttribLocation(prog2D, "vPosition");
vTC2D = GLES20.glGetAttribLocation(prog2D, "vTexCoord");
GLES20.glEnableVertexAttribArray(vPos2D);
GLES20.glEnableVertexAttribArray(vTC2D);
}
示例2: GLSurfaceFilter
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Constructor
* this should be called in GL context
*/
public GLSurfaceFilter() {
mCoordsPerVertex = 2;
mVertexStride = mCoordsPerVertex * SIZEOF_FLOAT; // 8
mVertexCount = FULL_RECTANGLE_COORDS.length / mCoordsPerVertex; //4
mTexCoordStride = 2 * SIZEOF_FLOAT; //8
hProgram = GLUtil.loadProgram(VERTEX_SHADER, FRAGMENT_SHADER);
mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES;
// get locations of attributes and uniforms
maPositionLoc = GLES20.glGetAttribLocation(hProgram, "aPosition");
GLUtil.checkLocation(maPositionLoc, "aPosition");
maTextureCoordLoc = GLES20.glGetAttribLocation(hProgram, "aTextureCoord");
GLUtil.checkLocation(maTextureCoordLoc, "aTextureCoord");
muMVPMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uMVPMatrix");
GLUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix");
muTexMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uTexMatrix");
GLUtil.checkLocation(muTexMatrixLoc, "uTexMatrix");
}
示例3: draw
import android.opengl.GLES20; //导入方法依赖的package包/类
public void draw() {
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glUseProgram(mProgram);
int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
GLES20.glEnableVertexAttribArray(mPositionHandle);
int vertexStride = COORDS_PER_VERTEX * 4;
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, mVertexBuffer);
GLES20.glUniform4fv(GLES20.glGetUniformLocation(mProgram, "aColor"), 1, mColor, 0);
GLES20.glUniform2f(GLES20.glGetUniformLocation(mProgram, "aCirclePosition"), mCenterX, mCenterY);
GLES20.glUniform1f(GLES20.glGetUniformLocation(mProgram, "aRadius"), mRadius);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, mDrawOrder.length, GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer);
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
示例4: onCreate
import android.opengl.GLES20; //导入方法依赖的package包/类
protected void onCreate(){
if(mRes!=null){
mGLProgram= GpuUtils.createGLProgramByAssetsFile(mRes,mVertex,mFragment);
}else{
mGLProgram= GpuUtils.createGLProgram(mVertex,mFragment);
}
mGLVertexCo= GLES20.glGetAttribLocation(mGLProgram,"aVertexCo");
mGLTextureCo=GLES20.glGetAttribLocation(mGLProgram,"aTextureCo");
mGLVertexMatrix=GLES20.glGetUniformLocation(mGLProgram,"uVertexMatrix");
mGLTextureMatrix=GLES20.glGetUniformLocation(mGLProgram,"uTextureMatrix");
mGLTexture=GLES20.glGetUniformLocation(mGLProgram,"uTexture");
if(isUseSize){
mGLWidth=GLES20.glGetUniformLocation(mGLProgram,"uWidth");
mGLHeight=GLES20.glGetUniformLocation(mGLProgram,"uHeight");
}
}
示例5: MyShader
import android.opengl.GLES20; //导入方法依赖的package包/类
/** Creates the shader. This will compile and link the shader. */
public MyShader() {
// Compile and link the shader program.
int vertexShader = MyGLUtils.loadShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_SOURCE);
int fragmentShader = MyGLUtils.loadShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_SOURCE);
program = GLES20.glCreateProgram();
GLES20.glAttachShader(program, vertexShader);
GLES20.glAttachShader(program, fragmentShader);
GLES20.glLinkProgram(program);
MyGLUtils.checkGlError("link program");
// Get the handles to our shader parameters.
GLES20.glUseProgram(program);
positionHandle = GLES20.glGetAttribLocation(program, "aPosition");
colorHandle = GLES20.glGetAttribLocation(program, "aColor");
mvpMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");
GLES20.glUseProgram(0);
MyGLUtils.checkGlError("get handles");
}
示例6: handle
import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
protected int handle() {
if (mHandle == 0) {
mHandle = GLES20.glGetAttribLocation(mProgram.handle, mName);
}
return mHandle;
}
示例7: glGetAttribLocation
import android.opengl.GLES20; //导入方法依赖的package包/类
public static int glGetAttribLocation(final int aProgramHandle, final String aAttributeName)
{
//.if DESKTOP
//|return gl.glGetAttribLocation(aProgramHandle, aAttributeName);
//.elseif ANDROID
return GLES20.glGetAttribLocation(aProgramHandle, aAttributeName);
//.endif
}
示例8: draw
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Encapsulates the OpenGL ES instructions for drawing this shape.
*
* @param mvpMatrix - The Model View Project matrix in which to draw
* this shape.
*/
public void draw(float[] mvpMatrix) {
// Add program to OpenGL environment
GLES20.glUseProgram(mProgram);
// get handle to vertex shader's vPosition member
mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
// Enable a handle to the triangle vertices
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Prepare the triangle coordinate data
GLES20.glVertexAttribPointer(
mPositionHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
vertexStride, vertexBuffer);
// get handle to fragment shader's vColor member
mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
// Set color for drawing the triangle
GLES20.glUniform4fv(mColorHandle, 1, color, 0);
// get handle to shape's transformation matrix
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
MyGLRenderer.checkGlError("glGetUniformLocation");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
MyGLRenderer.checkGlError("glUniformMatrix4fv");
// Draw the triangle
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
示例9: initShader
import android.opengl.GLES20; //导入方法依赖的package包/类
private void initShader(Context context) {
mVertexShader = ShaderUtil.loadFromAssetsFile("vertex_texture.sh" , context.getResources());
mFragShader = ShaderUtil.loadFromAssetsFile("frag_texture.sh" , context.getResources());
mProgram = ShaderUtil.createProgram(mVertexShader , mFragShader);
maPositionHandle = GLES20.glGetAttribLocation(mProgram , "aPosition");
maTexCoorHandle = GLES20.glGetAttribLocation(mProgram , "aTexCoor");
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram , "uMVPMatrix");
}
示例10: initShader
import android.opengl.GLES20; //导入方法依赖的package包/类
private void initShader(Context context) {
mVertexShader = ShaderUtil.loadFromAssetsFile("vertex_angle.sh" , context.getResources());
mFragShader = ShaderUtil.loadFromAssetsFile("frag_angle.sh" , context.getResources());
mProgram = ShaderUtil.createProgram(mVertexShader , mFragShader);
maPositionHandle = GLES20.glGetAttribLocation(mProgram , "aPosition");
maTexCoorHandle = GLES20.glGetAttribLocation(mProgram , "aTexCoor");
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram , "uMVPMatrix");
}
示例11: ImageProgram
import android.opengl.GLES20; //导入方法依赖的package包/类
public ImageProgram() {
mProgram = OpenGLUtils.loadProgram(VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE);
mAPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
mATextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoordinate");
mUTextureHandle = GLES20.glGetUniformLocation(mProgram, "uTexture");
mUMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
mUOpacityHandle = GLES20.glGetUniformLocation(mProgram, "uOpacity");
}
示例12: draw
import android.opengl.GLES20; //导入方法依赖的package包/类
public void draw(float[] mvpMatrix, float r, float g, float b, float a) {
// Add program to OpenGL environment
GLES20.glUseProgram(mProgram);
// get handle to vertex shader's vPosition member
int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
// Enable a handle to the triangle vertices
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Prepare the triangle coordinate data
int vertexStride = COORDS_PER_VERTEX * 4;
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
vertexStride, vertexBuffer);
// get handle to fragment shader's vColor member
int mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
// Set color for drawing the triangle
float[] color = {r,g,b,a};
GLES20.glUniform4fv(mColorHandle, 1, color, 0);
// get handle to shape's transformation matrix
int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
GLRenderer.checkGlError("glGetUniformLocation");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
GLRenderer.checkGlError("glUniformMatrix4fv");
// Draw the square
GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
示例13: ColorShaderProgram
import android.opengl.GLES20; //导入方法依赖的package包/类
public ColorShaderProgram(final Context context) {
super(context, R.raw.vertex, R.raw.fragment);
// Retrieve uniform locations for the shader program.
mUMatrixLocation = GLES20.glGetUniformLocation(mProgram, U_MATRIX);
// Retrieve attribute locations for the shader program.
mAPositionLocation = GLES20.glGetAttribLocation(mProgram, A_POSITION);
mAColorLocation = GLES20.glGetAttribLocation(mProgram, A_COLOR);
}
示例14: createOnGlThread
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Allocates and initializes OpenGL resources needed by the plane renderer. Must be
* called on the OpenGL thread, typically in
* {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
*
* @param context Needed to access shader source and texture PNG.
* @param gridDistanceTextureName Name of the PNG file containing the grid texture.
*/
public void createOnGlThread(Context context, String gridDistanceTextureName)
throws IOException {
int vertexShader = ShaderUtil.loadGLShader(TAG, context,
GLES20.GL_VERTEX_SHADER, R.raw.plane_vertex);
int passthroughShader = ShaderUtil.loadGLShader(TAG, context,
GLES20.GL_FRAGMENT_SHADER, R.raw.plane_fragment);
mPlaneProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(mPlaneProgram, vertexShader);
GLES20.glAttachShader(mPlaneProgram, passthroughShader);
GLES20.glLinkProgram(mPlaneProgram);
GLES20.glUseProgram(mPlaneProgram);
ShaderUtil.checkGLError(TAG, "Program creation");
// Read the texture.
Bitmap textureBitmap = BitmapFactory.decodeStream(
context.getAssets().open(gridDistanceTextureName));
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glGenTextures(mTextures.length, mTextures, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textureBitmap, 0);
GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
ShaderUtil.checkGLError(TAG, "Texture loading");
mPlaneXZPositionAlphaAttribute = GLES20.glGetAttribLocation(mPlaneProgram,
"a_XZPositionAlpha");
mPlaneModelUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_Model");
mPlaneModelViewProjectionUniform =
GLES20.glGetUniformLocation(mPlaneProgram, "u_ModelViewProjection");
mTextureUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_Texture");
mLineColorUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_lineColor");
mDotColorUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_dotColor");
mGridControlUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_gridControl");
mPlaneUvMatrixUniform = GLES20.glGetUniformLocation(mPlaneProgram, "u_PlaneUvMatrix");
ShaderUtil.checkGLError(TAG, "Program parameters");
}
示例15: draw
import android.opengl.GLES20; //导入方法依赖的package包/类
public void draw() {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a compile rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our pre-vertex lighting program.
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handle for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
// Calculate position of the light.
// Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0F, 0.0f);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// right
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
// left
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// top
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
// bottom
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
// center
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 1.0f);
drawCube();
// Draw a point to indicate the light.
GLES20.glUseProgram(mPointProgramHandle);
drawLight();
}