English 中文(简体)
• 如何将世界坐标转换成在开放式GLES2.0中的坐标
原标题:How to convert world coordinates to screen coordinates in OpenGL ES 2.0

我正在使用开放的GL ES 1.x代码确定我的投影坐标。

glMatrixMode(GL_PROJECTION); 

float width = 320;
float height = 480;

glOrthof(0.0,                  // Left
         1.0,                  // Right
         height / width,       // Bottom
         0.0,                  // Top
         -1.0,                 // Near
         1.0);                 // Far
glMatrixMode(GL_MODELVIEW);

What is the equivalent method to setup this in OpenGL ES 2.0 ? What projection matrix should I pass to the vertex shader ?

我已努力履行以下职能:建立汇总表,但不工作:

void SetOrtho (Matrix4x4& m, float left, float right, float bottom, float top, float near, 
float far)
{
    const float tx = - (right + left)/(right - left);
    const float ty = - (top + bottom)/(top - bottom);
    const float tz = - (far + near)/(far - near);

    m.m[0] = 2.0f/(right-left);
    m.m[1] = 0;
    m.m[2] = 0;
    m.m[3] = tx;

    m.m[4] = 0;
    m.m[5] = 2.0f/(top-bottom);
    m.m[6] = 0;
    m.m[7] = ty;

    m.m[8] = 0;
    m.m[9] = 0;
    m.m[10] = -2.0/(far-near);
    m.m[11] = tz;

    m.m[12] = 0;
    m.m[13] = 0;
    m.m[14] = 0;
    m.m[15] = 1;
}

Vertex Shader:

uniform mat4 u_mvpMatrix;

attribute vec4 a_position;
attribute vec4 a_color;

varying vec4 v_color;

void main()
{
   gl_Position = u_mvpMatrix * a_position;
   v_color = a_color;
}

客户法(直线透镜):

float min = 0.0f;
float max = 1.0f;
const GLfloat squareVertices[] = {
    min, min,
    min, max,
    max, min,
    max, max
};
const GLfloat squareColors[] = {
    1, 1, 0, 1,
    0, 1, 1, 1,
    0, 0, 0, 1,
    1, 0, 1, 1,
};
Matrix4x4 proj;
SetOrtho(proj, 0.0f, 1.0f, 480.0/320.0, 0.0f, -1.0f, 1.0f );

正在Peit模拟器中的产出一:

“entergraph

最佳回答

页: 1 Ortho公式看起来正确。

页: 1 如果能检查你重新确定转船旗为GL_TRUE,因为你将数据重新装入主要格式,而开放式GL预期主列(即,标准规则是,指数[0]是第一栏的顶,[3]是第一栏的底线,[4]是第二栏的顶点。

这或许也值得检查,如果你直接复制老的世界矩阵基点——你在你vert子中以正确的顺序重新采用模型论和预测,或者在万国邮联上正确 compos取,不管你如何重回。

问题回答

暂无回答




相关问题
OpenGL ES iPhone - drawing anti aliased lines

Normally, you d use something like: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glLineWidth(2.0f); glVertexPointer(2, GL_FLOAT, 0, points); ...

iPhone: Quartz2d vs. OpenGL ES

OK, I m still brand new to iPhone development. I have a free game on the app store, Winner Pong, but it s just a Pong clone (who would ve guessed) that uses the standard UIImageViews for the sprites. ...

GLPaint with white background

I m trying draw on a white background by reverse engineering GLPaint. I ve gone through every combination of kSaturation, kLuminosity and glBlendFunc, AND just about every combination I can think of ...

OpenGL ES - how to keep some object at a fixed size?

I m working on a little game in OpenGL ES. In the background, there is a world/map. The map is just a large texture. Zoom/pinch/pan is used to move around. And I m using glOrthof (left, right, bottom,...

Any free polygon library for the iPhone?

I need a library that can manage polygon modeling and basic transformation like rotating and translating. I d rather not redevelop everything from scratch Thanks

热门标签