我只是想了解这里发生了什么。我在屏幕上有一个纹理四边形,但我真的很困惑,为什么它占用了整个屏幕。如果我的纹理是64X64并且我想在屏幕左上方的四边形是64X64我需要更改什么?我的视口或顶点位置是否会占据整个屏幕?
到目前为止的变化:
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
myquad.loadGLTexture(gl, this.context);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(gl.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glDisable(GL10.GL_DEPTH_TEST);
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
width=w;
height=h;
gl.glViewport(0, 0, w, h);
gl.glLoadIdentity();
gl.glOrthof(0.0f, w, 0, h, -1.0f, 1.0f);
}
public void onDrawFrame(GL10 gl) {
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// clear the color buffer to show the ClearColor we called above...
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glLoadIdentity();
myquad.Draw(gl);
//gl.glTranslatef(.5f, 2.0f, 0.0f);
//gl.glScalef(.5f, .5f, 0);
}
private float vertices[] = {
// Vertices for the square
-1.0f, -1.0f, 0.0f, // 0. left-bottom
1.0f, -1.0f, 0.0f, // 1. right-bottom
-1.0f, 1.0f, 0.0f, // 2. left-top
1.0f, 1.0f, 0.0f // 3. right-top
};
private float texture[] = {
//Mapping coordinates for the vertices
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
};
public void Draw(GL10 gl)
{
// set the color for the triangle
gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
//Enable the vertex and texture state
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texturebuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexbuffer);
//gl.glTranslatex(-20, 0, 0);
// Draw the vertices as triangle strip
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
}
答案 0 :(得分:1)
现在您的投影设置错误了。如果你想绘制像处理像素一样,你会想......
这条线
gl.glOrthof(0.0f, w, -h, 0.0f, -1.0f, 1.0f);
更像这样
gl.glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f);
其中width和height是上下文的大小(以像素为单位)。
编辑:
gl.glOrthof(0.0f, w, -h, 0.0f, -1.0f, 1.0f);
必须在每次调用glLoadIdentity()后调用。
现在你必须调整你的顶点坐标。现在,它们设置为在屏幕左下角外渲染1px x 1xx框1px。