2013-10-09 2 views
0

저는 게임 엔진을 lwjgl로 작성하려고 시도 했었습니다. 렌더링 문제가있어서 도움이 필요합니다. 기본적으로 lwjgl-basics (GitHub의 mattdesl)에서 몇 가지 단계를 수행하고 텍스처를 렌더링하지 않는다는 점을 제외하고는 렌더러에서 텍스처 클래스와 섹션을 제작했습니다. 코드는 다음과 같습니다.LWJGL 텍스처가 렌더링되지 않습니다.

public void drawTexturedRectangle(float x1, float y1, float w, float h, Texture t){ 
     t.bind(); 
     GL11.glColor4f(1.0f, 0, 1.0f, 1.0f); 
     GL11.glBegin(GL11.GL_QUADS); 
     GL11.glTexCoord2f(0, 0); 
     GL11.glVertex2f(x1, y1); 
     GL11.glTexCoord2f(1.0f, 0); 
     GL11.glVertex2f(x1 + w, y1); 
     GL11.glTexCoord2f(1.0f, 1.0f); 
     GL11.glVertex2f(x1 + w, y1 + h); 
     GL11.glTexCoord2f(0, 1.0f); 
     GL11.glVertex2f(x1, y1 + h); 
     GL11.glEnd(); 
    } 

그것이 렌더링되는 곳입니다. 여기에 텍스처 클래스는 다음과 같습니다

package com.nightfall.morningside; 

import java.io.*; 
import java.net.URL; 
import java.nio.ByteBuffer; 

import de.matthiasmann.twl.utils.*; 

import org.lwjgl.opengl.*; 
import org.lwjgl.opengl.GL12.*; 
import org.lwjgl.BufferUtils; 

public class Texture { 
    public int width; 
    public int height; 
    public int id; 

    public Texture(URL pathToTexture){ 
     try { 
      InputStream pngstream = pathToTexture.openStream(); 
      PNGDecoder pngdecoder = new PNGDecoder(pngstream); 

      width = pngdecoder.getWidth(); 
      height = pngdecoder.getHeight(); 

      int bpp = 4; 

      ByteBuffer buffer = BufferUtils.createByteBuffer(bpp * width * height); 

      pngdecoder.decode(buffer, width * bpp, PNGDecoder.Format.RGBA); 

      buffer.flip(); 

      id = GL11.glGenTextures(); 

      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); 

      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); 
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); 
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); 
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); 

      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    public void bind(){ 
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); 
    } 
} 

TexturedRectangle 클래스 :

package com.nightfall.morningside.geometry; 

import com.nightfall.morningside.Texture; 
import com.nightfall.morningside.Textured; 

public class TexturedRectangle extends Rectangle implements Textured{ 
    public Texture texture; 

    public TexturedRectangle(float xone, float yone, float w, float h, Texture t) { 
     super(xone, yone, w, h); 
     texture = t; 
    } 

    public Texture getTexture() { 
     return texture; 
    } 

} 

Rectangle 클래스 :

package com.nightfall.morningside.geometry; 

public class Rectangle { 
    private float x1; 
    private float y1; 
    private float width; 
    private float height; 

    public Rectangle(float xone, float yone, float w, float h){ 
     x1 = xone; 
     y1 = yone; 
     width = w; 
     height = h; 
    } 

    public float getX1(){ 
     return x1; 
    } 

    public float getY1(){ 
     return y1; 
    } 

    public float getHeight(){ 
     return height; 
    } 

    public float getWidth(){ 
     return width; 
    } 

    public Point getLocation(){ 
     return new Point(x1, y1); 
    } 
} 

그리고 질감 인터페이스 :

package com.nightfall.morningside; 

public interface Textured { 
    public Texture getTexture(); 
} 

그리고 Point 클래스 :

package com.nightfall.morningside.geometry; 

public class Point { 
    private float x1; 
    private float y1; 

    public Point(float x, float y){ 
     x1 = x; 
     y1 = y; 
    } 

    public float getX(){ 
     return x1; 
    } 

    public float getY(){ 
     return y1; 
    } 
} 

나는 이것이 모두이기를 바랍니다. 렌더링 방식과 관련하여 문제가 있다고 생각하지만 텍스처를로드하는 위치에 문제가있을 수 있습니다. 다른 것이 필요한 경우 알려 드리겠습니다. 감사합니다. .

+0

오, 명확히하기 위해 wjgl 2.90 – cstream24

+0

엔진을 만드는 경우 사용되지 않는 OpenGL 메소드를 모두 사용하지 마십시오. – Vallentin

+0

나는 배우기 위해 그것을하고있다. 나는 내가 실제로 그것을 할 수 있다고 확신하는대로 모든 것을 바꿀 것이다. – cstream24

답변

0

텍스처는 기본적으로 사용 중지됩니다. 당신은 질감 원시 (예를 들어 질감 쿼드)를 렌더링 할 때

glEnable(GL_TEXTURE2D); 
glBindTexture(GL_TEXTURE_2D, textureId); 

첫 번째 줄은 텍스처를 사용하는 OpenGL을 알려줍니다과 텍스처링을 활성화해야합니다, 두 번째 사용할 텍스처를 지정.

질감의 사용을 중지하려면

, 당신은 할 수 있습니다 : 제로 GL_TEXTURE_2D하는

  • 바인딩 : glBindTexture(GL_TEXTURE_2D, 0);또는
  • 안 GL_TEXTURE_2D을 : glDisable(GL_TEXTURE_2D);

편집, 나는 모든 GLxx. 접두사를 잊어 버렸습니다 (내 코드에서 정적 가져 오기)

+0

'glBindTexture' 0을 핸들로 줄 수는 없으므로 실제 핸들을 제공해야합니다. – Vallentin

+0

사실, 이제는 더 이상 사용되지 않지만 텍스처를 바인딩 해제한다는 의미입니다. OP는 즉각적인 모드를 사용합니다. glBindTexture (X, 0)는 정상적으로 작동하고 정상적으로 작동하며 문제를 해결해줍니다. http://www.talisman.org/opengl-1.1/Reference/glBindTexture.html을 참조하십시오. –

+0

오, 나는 당신이 그에게 질감을 묶는 방법이라고 말했다고해도, 나는 그것을 보지 못했다는 것을 당신이 생각하지 않는다고 생각하지 않았습니다. 오해 때문에 유감스럽게 생각합니다. – Vallentin

관련 문제