我目前正在学习android的opengl es。我读过很多教程说坐标系是从-1f-1f(左下角)到1f-1f右上角。我能搞清楚的就这么多。但我目前正在试验的问题是,当我尝试调整三角形的大小时:窗口似乎正在根据我的极值调整自身的大小。如果这是我试图画的唯一的三角形,在两个不同的例子上
0f,0f,
0华氏度,0.01华氏度,
0.01华氏度,0.01华氏度
三角形和
0f,0f
0f、1f
一楼,一楼
老实说,我有点迷路了。这是我的代码:int vertexshaderid,fragmentshaderid;
int[] result = new int[1];
_vertexSize = 2;
_verticeCount = 3;
_context = context;
vertexShaderID = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
fragmentShaderID = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
GLES20.glShaderSource(vertexShaderID, _context.getString(R.string.vertexShader));
GLES20.glShaderSource(fragmentShaderID, _context.getString(R.string.fragmentShader));
_programID = GLES20.glCreateProgram();
GLES20.glCompileShader(vertexShaderID);
GLES20.glGetShaderiv(vertexShaderID, GLES20.GL_COMPILE_STATUS, result,0);
GLES20.glCompileShader(fragmentShaderID);
GLES20.glGetShaderiv(fragmentShaderID, GLES20.GL_COMPILE_STATUS, result,0);
GLES20.glAttachShader(_programID, vertexShaderID);
GLES20.glAttachShader(_programID, fragmentShaderID);
GLES20.glLinkProgram(_programID);
GLES20.glGetProgramiv(_programID, GLES20.GL_LINK_STATUS, result, 0);
GLES20.glValidateProgram(_programID);
GLES20.glGenBuffers(1,result,0);
vertexBufferID = result[0];
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferID);
FloatBuffer coordBuffer = FloatBuffer.allocate(_vertexSize * _verticeCount);
coordBuffer.put(coords);
coordBuffer.position(0);
Log.d("count", "" + SIZEOF_FLOAT * _verticeCount * _vertexSize);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, SIZEOF_FLOAT * _verticeCount * _vertexSize, coordBuffer, GLES20.GL_DYNAMIC_DRAW);
coordBuffer.clear();
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(0,2,GLES20.GL_FLOAT, true,2 * SIZEOF_FLOAT,0);
Log.d("version", GLES20.glGetString(GLES20.GL_VERSION));
我也试着取代 GLES20.glVertexAttribPointer(0,2,GLES20.GL_FLOAT, true,2 * SIZEOF_FLOAT,0);
由 GLES20.glVertexAttribPointer(0,2,GLES20.GL_FLOAT, false,2 * SIZEOF_FLOAT,0);
事先谢谢你的帮助
p、 这是我的着色器 attribute highp vec2 inPosition; void main() { gl_Position = vec4(inPosition.x, inPosition.y,0.0,0.0) ; }
1条答案
按热度按时间v64noz0r1#
找出我犯的错误:我的着色器错了。glu位置的depth参数被设置为0,所以我猜不管发生什么,它都会超出屏幕。
gl_Position.xy = inPosition;
如果可以的话GLES20.glVertexAttribPointer(0,2,GLES20.GL_FLOAT, false,2 * SIZEOF_FLOAT,0);
. 如果第四个参数为真,它将重新缩放它。