English 中文(简体)
和机器人 OpenGL ES ORTHO 异端比
原标题:Android OpenGL ES ortho strange aspect ratio

我对 OpenGL ES 相当陌生,我正试图绘制一些纹理的四舍五入。我想保留它 2D,所以我决定使用正方图投影。我真正想要的,是绘制一个平面,在每一个设备上都使用同样的相对屏幕空间,不管屏幕分辨率如何。

我遇到的问题是拼图投影的设置。 侧比不正确。 方形是高度的矩形 。 这是我到目前为止的代码 :

发件人:

// automatically looped by android
public void onDrawFrame(GL10 gl) {
    // clear screen and buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

    // Draw elements
    for (GameObject object : level.getGameObjects()) {
        gl.glScalef(0.2f, 0.2f, 0.0f);
        object.draw(gl);
        gl.glLoadIdentity();
    }
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    gl.glOrthof(0f, 480f, 0f, 800f, -1f, 1f);

}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // Load all textures
    for (GameObject object : level.getGameObjects()) {
        object.bindTexture(gl);
    }

    // Initialize game canvas
    gl.glEnable(GL10.GL_TEXTURE_2D); // Enable Texture Mapping
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black background

    // enable texture transparency
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA,   GL10.GL_ONE_MINUS_SRC_ALPHA);               
}   

绘图方法与本教程中的方法完全相同:http://obviam.net/index.php/texture-mapping-opengl-android-displaying-images-using-opengl-and-squares/

Kind regards, Daan

最佳回答

我找到了我问题的答案。 首先,我硬化了宽度和高度的编码,但这不是一个好选择。要对所有屏幕分辨率都有一个固定的代码,i 现在计算宽比, 并且计算高度, 我使用乘以宽比乘以宽比 。

另一个问题是,在确定glortho之前,我没有重设投影矩阵。 我改变了这一切,它解决了问题:

public void onSurfaceChanged(GL10 gl, int width, int height) {      
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(0f, 320, 0f, 320*aspect, -1f, 1f);
}

我希望这对某人有帮助

Kind regards, Daan

问题回答

为什么你要用硬码将宽度和高度编码到正正统? 您应该用宽度和高度来使用经过的宽度和高度吗? @ info: whatsthis

gl.gl东正教( 0f, 宽度, 0f, 高度, -1f, 1f);

Looks like you ve solved it. Can you provide details on how you calculated the aspect variable (a division of height and width perhaps?) Just as an FYI, the height and width values passed in to the onSurfaceChanged() event are indeed dynamic. For instance, they are reversed when you flip the screen orientation. I m relatively new to this as well, but in my desktop gl experience, it s important to factor these in when a window size changes.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签