Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added in code for lesson six

  • Loading branch information...
commit a66b8214a20a1f8b8cebb2451310e9513a5d3a52 1 parent a380576
@alihelmy authored
Showing with 7 additions and 28 deletions.
  1. +7 −28 LessonSix/com/onehandstand/lwjgltutorial/lessonsix/Cube.java
View
35 LessonSix/com/onehandstand/lwjgltutorial/lessonsix/Cube.java
@@ -45,6 +45,7 @@
private Vector3f position, rotation;
private static int shader;
private static final String TEXTURES_ROOT_PATH="textures"+File.separator;
+ private Texture texture;
public Cube() {
position=new Vector3f(0f, 0f, -4f);
@@ -54,7 +55,7 @@ public Cube() {
}
private Texture initTextures() {
- Texture texture=null;
+ texture=null;
try {
texture=TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(TEXTURES_ROOT_PATH+"crate.png"));
} catch (IOException e) {
@@ -90,35 +91,10 @@ private void initShaderAttributes() {
private void initBuffers() {
setupVertexAttributesBuffer();
- setupTextureBuffer();
+ initTextures();
setupVertexIndecesBuffer();
}
- private void setupTextureBuffer() {
- Texture texture=initTextures();
- if (texture!=null) {
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
-
- texture.bind();
- ByteBuffer textureData=getTextureByteData(texture);
-
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D,
- GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
-
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,
- (int)texture.getWidth(), (int)texture.getHeight(), 0,
- GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, textureData);
- }
- }
-
- private ByteBuffer getTextureByteData(Texture texture) {
- byte[] textureDataArray=texture.getTextureData();
- ByteBuffer textureData=BufferUtils.createByteBuffer(textureDataArray.length);
- textureData.put(textureDataArray);
- textureData.flip();
- return textureData;
- }
-
private void setupVertexIndecesBuffer() {
vertexIndicesBufferID=glGenBuffersARB();
// put in vertex index data
@@ -198,7 +174,10 @@ public void draw() {
//bind the uniform attributes
ARBShaderObjects.glUniform3fARB(modelPositionAttributeIndex, position.x, position.y, position.z);
ARBShaderObjects.glUniform3fARB(modelRotationAttributeIndex, rotation.x, rotation.y, rotation.z);
- ARBShaderObjects.glUniform1iARB(textureSamplerIndex, GL13.GL_TEXTURE0);
+
+ GL13.glActiveTexture(GL13.GL_TEXTURE0);
+ texture.bind();
+// ARBShaderObjects.glUniform1iARB(textureSamplerIndex, GL13.GL_TEXTURE0);
// pass in info to vertex shader
int dataOffset=0;
Please sign in to comment.
Something went wrong with that request. Please try again.