
gl_position = uMVPMatrix * vposition;
至:
gl_position = vposition;
将应用程序放回第一部分(根据屏幕方向,三角形延伸).任何想法是什么问题?这是我到目前为止的代码,以防万一我错过了一些东西:
public class GLTest20Renderer implements Renderer { private final String vertexshadercode = // This matrix member variable provIDes a hook to manipulate // the coordinates of the objects that use this vertex shader "uniform mat4 uMVPMatrix; \n" + "attribute vec4 vposition; \n" + "voID main(){ \n" + // the matrix must be included as a modifIEr of gl_position " gl_position = uMVPMatrix * vposition; \n" + "} \n"; private final String fragmentshadercode = "precision mediump float; \n" + "voID main(){ \n" + " gl_Fragcolor = vec4 (0.63671875,0.76953125,0.22265625,1.0); \n" + "} \n"; private floatBuffer triangleVB; private int mProgram; private int mapositionHandle; private int muMVPMatrixHandle; private float[] mMVPMatrix = new float[16]; private float[] mMMatrix = new float[16]; private float[] mVMatrix = new float[16]; private float[] mProjMatrix = new float[16]; public voID onSurfaceCreated(GL10 unused,EGLConfig config) { GLES20.glClearcolor(0.5f,0.5f,1.0f); initShapes(); int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,vertexshadercode); int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,fragmentshadercode); mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program GLES20.glAttachShader(mProgram,vertexShader); // add the vertex shader to program GLES20.glAttachShader(mProgram,fragmentShader); // add the fragment shader to program GLES20.gllinkProgram(mProgram); // creates OpenGL program executables // get handle to the vertex shader's vposition member mapositionHandle = GLES20.glGetAttribLocation(mProgram,"vposition"); } public voID onDrawFrame(GL10 unused) { GLES20.glClear( GLES20.GL_color_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT ); // Add program to OpenGL environment GLES20.gluseProgram(mProgram); // Prepare the triangle data GLES20.glVertexAttribPointer(mapositionHandle,3,GLES20.GL_float,false,12,triangleVB); GLES20.glEnabLevertexAttribarray(mapositionHandle); // Apply a ModelVIEw Projection transformation Matrix.multiplyMM(mMVPMatrix,mProjMatrix,mVMatrix,0); GLES20.gluniformMatrix4fv(muMVPMatrixHandle,1,mMVPMatrix,0); // Draw the triangle GLES20.glDrawArrays(GLES20.GL_TRIANGLES,3); } public voID onSurfaceChanged(GL10 unused,int wIDth,int height) { GLES20.glVIEwport(0,wIDth,height); float ratio = (float) wIDth / height; Matrix.frustumM(mProjMatrix,-ratio,ratio,-1,7); muMVPMatrixHandle = GLES20.glGetUniformlocation(mProgram,"uMVPMatrix"); Matrix.setLookAtM(mVMatrix,-3,0f,1.0f,0.0f); } private voID initShapes() { float triangleCoords[] = { // X,Y,Z -0.5f,-0.25f,0.0f,0.559016994f,0 }; // initialize vertex Buffer for triangle ByteBuffer vbb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) triangleCoords.length * 4); vbb.order(ByteOrder.nativeOrder());// use the device harDWare's native byte order triangleVB = vbb.asfloatBuffer(); // create a floating point buffer from the ByteBuffer triangleVB.put(triangleCoords); // add the coordinates to the floatBuffer triangleVB.position(0); // set the buffer to read the first coordinate } private int loadShader(int type,String shadercode) { // create a vertex shader type (GLES20.GL_VERTEX_SHADER) // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER) int shader = GLES20.glCreateShader(type); // add the source code to the shader and compile it GLES20.glShaderSource(shader,shadercode); GLES20.glCompileShader(shader); return shader; }} 我正在三星galaxy S2上运行所有这些.
解决方法 修正了,只是将观察点的近点改为3:Matrix.frustumM(mProjMatrix,2,7);总结
以上是内存溢出为你收集整理的java – Android的OpenGL ES教程似乎不起作用全部内容,希望文章能够帮你解决java – Android的OpenGL ES教程似乎不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)