Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- glEnable(GL_TEXTURE_2D);
- // Generate a texture handle.
- int textureID = glGenTextures();
- // Bind the texture to the global slot for 2D textures.
- glBindTexture(GL_TEXTURE_2D, textureID);
- // Set the texture magnification settings to 'nearest'.
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- try {
- InputStream textureInputStream;
- try{
- textureInputStream = new FileInputStream("D:/Downloads/mcp/games/lwjgl/res/sample_image.png");
- }catch (Exception e){
- System.out.println("Error:");
- e.printStackTrace();
- System.out.println("Error:");
- return;
- }
- System.out.println(textureInputStream);
- PNGDecoder textureDecoder = new PNGDecoder(textureInputStream);
- ByteBuffer textureBuffer = BufferUtils.createByteBuffer(3 * textureDecoder.getWidth() * textureDecoder.getHeight());
- textureDecoder.decode(textureBuffer, textureDecoder.getWidth() * 3, PNGDecoder.Format.RGB);
- textureBuffer.flip();
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureDecoder.getWidth(),
- textureDecoder.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, textureBuffer);
- textureInputStream.close();
- glBindTexture(GL_TEXTURE_2D, lookupTexture);
- }catch (Exception e){
- }
- glNewList(heightmapDisplayList, GL_COMPILE);
- for (int z = 0; z < data.length - 1; z++) {
- glBegin(GL_TRIANGLE_STRIP);
- // The t texture coordinate for z and z + 1
- float t0 = (float)z / (data.length - 1); // t0 in [0,1]
- float t1 = (float)(z + 1) / (data.length - 1); // t1 in [0,1]
- for (int x = 0; x < data[z].length; x++) {
- // The s texture coordinate for x
- float s = (float)x / (data[z].length - 1); // s in [0, 1]
- glVertex3f(x, data[z][x], z);
- glTexCoord2f(s, t0);
- glVertex3f(x, data[z + 1][x], z + 1);
- glTexCoord2f(s, t1);
- }
- glEnd();
- }
- glEndList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement