OpenGL 용 lwjgl 텍스처 아틀라스를 쓰고 있습니다. 텍스처 아트 레이션을 잘 만들었지 만 렌더 할 때 객체가 나타나지만 완전히 검은 색입니다. 내 텍스처 좌표가 내 텍스처 맵의 빈 섹션에 있기 때문에 이렇게 생각합니다. 블렌딩을 올바르게 설정하지 않았고 객체가 렌더링되는 첫 번째 객체이기 때문에 알파가 완전히 검은 색이됩니다. 내가 0,0,0에서 테스트 쿼드를 렌더링하고 객체의 윤곽을 볼 수 있기 때문에 이것을 알 수 있습니다. 다른 순서로 렌더링했을 때 그 윤곽은 거기에 없었습니다. 그 시간에 블렌딩이 제대로 작동했기 때문입니다. 다음은 좌표를 변경하는 좌표 변환 코드입니다. m_height 및 m_width는 전체 텍스처 아트의 높이 및 너비이며 x, y, w 및는 아트라스의 텍스처 위치, 폭 및 높이입니다. x, y는 왼쪽 위 모서리에 있고, texCoordinate2D는 내가 믿는 왼쪽 하단에 있습니다. 이것이 내가 m_height-yh를하는 이유입니다. 아틀라스가 아닌 일반적인 질감으로 잘 작동합니다. 여기 텍스처 아틀라스 텍스처 좌표계
public TexCoordinate2D getTextureCoord(int x, int y, int w, int h,
TexCoordinate2D coord) {
int nx = x;
int ny = (m_height - y) - h;
//to fix m_repeat
float cx = coord.getX();//going to fix repeat here
float cy = coord.getY();
int cpx = (int) (nx + (cx * w));
int cpy = (int) (ny + (cy * h));
float ncoordx = cpx/(float) m_width;
float ncoordy = cpy/(float) m_height;
System.out.println("Rect: " + x + " " + y + " " + w + " " + h);
System.out.println("Coord: x: " + coord.getX() + " y: " + coord.getY());
System.out.println("Coord--> pixel: x: " + cpx + " y: " + cpy);
System.out.println("Pixel-->Coord: x: " + ncoordx + " y: " + ncoordy);
TexCoordinate2D newCoord = new TexCoordinate2D(ncoordx, ncoordy);
m_coordinates.add(newCoord);
return newCoord;
}
은 일부 출력
Rect: 0 0 512 512 #The rectangle from the top left corner of atlas
Coord: x: 0.5004405 y: 0.55040383 #The input coord from bottom left corner of texture
Coord--> pixel: x: 256 y: 3865 #The pixel location in the atlas of the input coord the from bottom left corner
Pixel-->Coord: x: 0.0625 y: 0.9436035 #The coordinates in the atlas (The finished product)
Rect: 3072 0 256 256 #Starts again
Coord: x: 0.56088686 y: 0.5795429
Coord--> pixel: x: 3215 y: 3988
Pixel-->Coord: x: 0.7849121 y: 0.9736328
Rect: 2560 0 512 512
Coord: x: 0.18178056 y: 0.35738176
Coord--> pixel: x: 2653 y: 3766
Pixel-->Coord: x: 0.6477051 y: 0.9194336
그래서 버그가 무엇입니까?
이 예제에서 텍스처 좌표 계산을 확인하는 데 문제가 있습니까, 어떤 해상도 텍스처 맵을 사용하고 있습니까? –
4096x4096 텍스처를 사용하고 있습니다. 거대한 하나의 – Vastsuperking