방금 Java로 OpenGL을 시험해보기 시작했습니다. 나는 LWJGL과 Slick-Util Library를 다운로드했다. 이제 화면에서 꽤 잘 작동하는 일부 이미지를 칠하려고합니다. 하지만 큰 문제가 있습니다 OpenGL 회전 및 크기 문제
난 내 이미지를 회전하고 회전 얻을 같은 이미지를 가진 spritesheet처럼 당신이 코너에서 같은 이미지의 일부 비트를 볼 수 °는 약 45이다
.이미지 크기를 조정하려면 어떻게해야합니까? 꽤 작으며 glScale() func은 이미지 자체의 크기를 조정하지만 인쇄되는 공간은 조정하지 않습니다. 이미지가 16 * 16 픽셀의 크기를 가지고 있으며, 내가 그것을 확장 그렇다면 난 그냥에서 조정 된 이미지의 일부를 볼 수있는 16 *
가 여기에 OpenGL을위한 내 코드의 16pixels :
public class Widget {
String name;
int angle;
public Texture image_texture;
public String image_path ;
public int image_ID;
public int cord_x = 0;
public int cord_y = 0;
static LinkedList<Widget> llwidget = new LinkedList<Widget>();
public Widget(String path){
llwidget.add(this);
image_path = path;
try {
image_texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(image_path), GL_NEAREST);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
};
image_ID = image_texture.getTextureID();
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0,Display.getWidth(),Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Display.getWidth(),Display.getHeight(), 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
}
void render(){
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f,0.5f,0.0f);
//! Graphics bug
glRotatef(angle,0.0f,0.0f,1.0f);
//
glTranslatef(-0.5f,-0.5f,0.0f);
//! Doesn't work
glScalef(2f, 2f, 2f);
//
glMatrixMode(GL_MODELVIEW);
Color.white.bind();
image_texture.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(cord_x, Display.getHeight() - cord_y);
glTexCoord2f(1,0);
glVertex2f(cord_x+image_texture.getTextureWidth(),Display.getHeight() - cord_y);
glTexCoord2f(1,1);
glVertex2f(cord_x+image_texture.getTextureWidth(),Display.getHeight() - cord_y+image_texture.getTextureHeight());
glTexCoord2f(0,1);
glVertex2f(cord_x,Display.getHeight() - cord_y+image_texture.getTextureHeight());
glEnd();
}
}
"모서리에서 같은 이미지의 비트"를 보면서 무엇을 기대 했습니까? 텍스처 좌표가 [** 0 **, ** 1 **] 범위를 벗어나는 경우의 기본 동작은 텍스처를 반복하는 것입니다. 좌표를 200 % 스케일 한 다음 ** - 0.5 ** 오프셋을 적용하고 회전 시켜서이 상황을 만드는 것이 좋습니다. 아마도 여러분은 * modelview * 행렬에 이러한 변환 중 일부를 적용하고, 원하는 것을 설명하여 판단해야합니다. –