Aşağıdaki kod OpenGL ES2'yi kullanarak 2D ekran alanında bir dikdörtgen çizer. Dikdörtgenin çizimini, köşelerini değiştirmeden 1 piksel sağa nasıl hareket ettirirsiniz?OpenGL Orthographic Projeksiyon ve Çevirme
Özellikle, yapmaya çalıştığım şey koordinatları 0,5 piksel sağa kaydırmaktır. Bunu daha önce GLES1.x ile yapmak zorunda kaldım ve bunun sebebi, 0.5t ile glTranslate() yapmadığım sürece doğru yerde çizgiler çizme problemleri yaşadım.
Aşağıdaki kodda glm :: translate() kullanımı konusunda kafam karıştı.
0.5f'lik bir çevirmeyi denerseniz, tüm dikdörtgen ekranın solundan ortaya doğru hareket eder - yaklaşık 200 piksellik bir atlama.
Modelde veya Görünüm matrisinde bir glm :: translate yapsam da aynı sonucu elde ediyorum.
Matris çarpımının sırası yanlış mı ve ne olmalıdır?
attribute vec4 vPosition;
uniform mat4 MVP;
void main()
{
gl_Position = MVP * vPosition;
}
GÜNCELLEME: Burada
short g_RectFromTriIndices[] =
{
0, 1, 2,
0, 2, 3
}; // The order of vertex rendering.
GLfloat g_AspectRatio = 1.0f;
//--------------------------------------------------------------------------------------------
// LoadTwoTriangleVerticesForRect()
//--------------------------------------------------------------------------------------------
void LoadTwoTriangleVerticesForRect(GLfloat *pfRectVerts, float fLeft, float fTop, float fWidth, float fHeight)
{
pfRectVerts[ 0 ] = fLeft;
pfRectVerts[ 1 ] = fTop;
pfRectVerts[ 2 ] = 0.0;
pfRectVerts[ 3 ] = fLeft + fWidth;
pfRectVerts[ 4 ] = fTop;
pfRectVerts[ 5 ] = 0.0;
pfRectVerts[ 6 ] = fLeft + fWidth;
pfRectVerts[ 7 ] = fTop + fHeight;
pfRectVerts[ 8 ] = 0.0;
pfRectVerts[ 9 ] = fLeft;
pfRectVerts[ 10 ] = fTop + fHeight;
pfRectVerts[ 11 ] = 0.0;
}
//--------------------------------------------------------------------------------------------
// Draw()
//--------------------------------------------------------------------------------------------
void Draw(void)
{
GLfloat afRectVerts[ 12 ];
//LoadTwoTriangleVerticesForRect(afRectVerts, 0, 0, g_ScreenWidth, g_ScreenHeight);
LoadTwoTriangleVerticesForRect(afRectVerts, 50, 50, 100, 100);
// Correct for aspect ratio so squares ARE squares and not rectangular stretchings..
g_AspectRatio = (GLfloat) g_ScreenWidth/(GLfloat) g_ScreenHeight;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLuint hPosition = glGetAttribLocation(g_SolidProgram, "vPosition");
// PROJECTION
glm::mat4 Projection = glm::mat4(1.0);
// Projection = glm::perspective(45.0f, g_AspectRatio, 0.1f, 100.0f);
// VIEW
glm::mat4 View = glm::mat4(1.0);
static GLfloat transValY = 0.5f;
static GLfloat transValX = 0.5f;
//View = glm::translate(View, glm::vec3(transValX, transValY, 0.0f));
// MODEL
glm::mat4 Model = glm::mat4(1.0);
// static GLfloat rot = 0.0f;
// rot += 0.001f;
// Model = glm::rotate(Model, rot, glm::vec3(0.0f, 0.0f, 1.0f)); // where x, y, z is axis of rotation (e.g. 0 1 0)
glm::mat4 Ortho = glm::ortho(0.0f, (GLfloat) g_ScreenWidth, (GLfloat) g_ScreenHeight, 0.0f, 0.0f, 1000.0f);
glm::mat4 MVP;
MVP = Projection * View * Model * Ortho;
GLuint hMVP;
hMVP = glGetUniformLocation(g_SolidProgram, "MVP");
glUniformMatrix4fv(hMVP, 1, GL_FALSE, glm::value_ptr(MVP));
glEnableVertexAttribArray(hPosition);
// Prepare the triangle coordinate data
glVertexAttribPointer(hPosition, 3, GL_FLOAT, FALSE, 0, afRectVerts);
// Draw the rectangle using triangles
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, g_RectFromTriIndices);
glDisableVertexAttribArray(hPosition);
}
tepe tarayıcı kaynağıdır aşağıda matris çarpım beni daha iyi sonuçlar veriyor buluyorum. Bu olmasa da "doğru" ya da eğer bilmiyorum: MVP bana gerçekten garip görünüyor Yani
MVP = Ortho * Model * View * Projection;