2015-02-05 2 views
0

제 목표는 Linux, Windows 및 Android 용 C++로 게임을 작성하는 것입니다. 저는 SDL을 사용하고 OpenGL ES 2.0 및 셰이더를 사용하여 기본 기하학적 모양을 그릴 수 있습니다. 그러나 내가 인식하는 이러한 모양에 텍스처를 적용하려고하면 안드로이드에서 더 크고 불완전하게 보입니다. PC에서 잘 작동합니다. 내 코드를 Android 용으로 컴파일 할 필요가 없습니다. 우분투 14.10을 사용하고 Android 5.0.1을 사용하는 Nexus 5에서도 테스트합니다.왜 안드로이드에 텍스처가 PC에 비해 더 크고 icomple하게 표시됩니까?

영역 x 0.0에서 1.0 및 y 0.0에서 0.5625 사이의 가로 세로 비율이 16 : 9 인 "표면"을 제공하는 정사영 프로젝션 매트릭스를 설정했습니다. TextureComparison1.png - Dropbox

가 그럼 난 사각형을 그리고 그것에 텍스처 매핑 : 결과는 다음과 같다

//Clear 
glClearColor(0.25, 0.0, 0.0, 1.0); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

//Configure viewport 
glViewport(0, 0, this->width, this->height); 

//Update matrices 
this->baseShader.bind(); 
this->baseShader.updateProjectionMatrix(this->matrix); 
this->matrix.loadIdentity(); 
this->baseShader.updateModelViewMatrix(this->matrix); 

//Draw rectangle 
GLfloat vertices[] = {0.0, 0.0, 0.0, 0.5625, 1.0, 0.0, 1.0, 0.5625}; 

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices); 
glEnableVertexAttribArray(0); 
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

glDisableVertexAttribArray(0); 

을 :이 지역에서 나는 "사용자 정의 공간"을 확인하기 위해 사각형을 그립니다. 여기에 코드입니다 :

//Enable blending 
bw::Texture::enableAlpha(); 

//Matrices 
this->textureShader.bind(); 
this->textureShader.updateProjectionMatrix(this->matrix); 
this->matrix.loadIdentity(); 

this->matrix.translate(this->sW/2.0, this->sH/2.0, 0.0); 
this->matrix.rotate(rot, 0.0, 0.0, 1.0); 
this->matrix.translate(-this->sW/2.0, -this->sH/2.0, 0.0); 

this->textureShader.updateModelViewMatrix(this->matrix); 

//Coordinates 
float x3 = this->sW/2.0-0.15, x4 = this->sW/2.0+0.15; 
float y3 = this->sH/2.0-0.15, y4 = this->sH/2.0+0.15; 
GLfloat vertices2[] = {x3, y3, x3, y4, x4, y3, x4, y4}; 
GLfloat texCoords[] = {0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0}; 

//Send coordinations to GPU 
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices2); 
glEnableVertexAttribArray(0); 

glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texCoords); 
glEnableVertexAttribArray(1); 

//Bind texture 
int u1 = glGetUniformLocation(this->textureShader.getId(), "u_Texture"); 
glActiveTexture(GL_TEXTURE0); 
this->spriteTexture.bind(); 
glUniform1i(u1, 0); 

//Draw 
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

glDisableVertexAttribArray(0); 
glDisableVertexAttribArray(1); 

그러나 이것은 나에게 다른 결과를 제공합니다

TextureComparison2.png - Dropbox

그럼 내가 수정하고 텍스처 좌표와 주변 테스트하기 위해 노력했다. 반으로 나누면 1.0s에서 0.5로 모두 내 텍스처의 "1 필드"만 표시해야합니까? 리눅스에서는 그런 방식이지만 안드로이드에서는 표시되는 텍스처의 임의의 임의 영역 만 있습니다.

아무도 내가 뭘 잘못했는지 힌트를 줄 수 있습니까?

+0

텍스처의 크기는 어느 정도입니까? OpenGL ES에는 몇 가지 제한 사항이 있습니까? –

+0

내 테스트 텍스처의 크기는 128x128입니다. 그래서 양측의 힘은 2입니다. – peter

답변

0

문제점을 파악했습니다. 내 속성은 a_Vertex를 0으로, a_TexCoordinate는 1로 바인딩합니다. PC에서는 발생하지만 Android에서는 안됩니다. 그래서 glBindAttribLocation에 대한 OpenGL ES 2.0 참고 자료를 살펴 보았습니다. 프로그램을 연결하기 전에 위치를 연결해야합니다. 이제 PC와 마찬가지로 Android에서도 완벽하게 작동합니다.

관련 문제