Advertisement
Guest User

Untitled

a guest
Aug 31st, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. glEnable(GL_TEXTURE_2D);
  2. // Generate a texture handle.
  3. int textureID = glGenTextures();
  4. // Bind the texture to the global slot for 2D textures.
  5. glBindTexture(GL_TEXTURE_2D, textureID);
  6. // Set the texture magnification settings to 'nearest'.
  7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  9. try {
  10. InputStream textureInputStream;
  11. try{
  12. textureInputStream = new FileInputStream("D:/Downloads/mcp/games/lwjgl/res/sample_image.png");
  13. }catch (Exception e){
  14. System.out.println("Error:");
  15. e.printStackTrace();
  16. System.out.println("Error:");
  17. return;
  18. }
  19.  
  20. System.out.println(textureInputStream);
  21. PNGDecoder textureDecoder = new PNGDecoder(textureInputStream);
  22. ByteBuffer textureBuffer = BufferUtils.createByteBuffer(3 * textureDecoder.getWidth() * textureDecoder.getHeight());
  23. textureDecoder.decode(textureBuffer, textureDecoder.getWidth() * 3, PNGDecoder.Format.RGB);
  24. textureBuffer.flip();
  25. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureDecoder.getWidth(),
  26. textureDecoder.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, textureBuffer);
  27. textureInputStream.close();
  28. glBindTexture(GL_TEXTURE_2D, lookupTexture);
  29. }catch (Exception e){
  30.  
  31. }
  32.  
  33.  
  34. glNewList(heightmapDisplayList, GL_COMPILE);
  35. for (int z = 0; z < data.length - 1; z++) {
  36. glBegin(GL_TRIANGLE_STRIP);
  37. // The t texture coordinate for z and z + 1
  38. float t0 = (float)z / (data.length - 1); // t0 in [0,1]
  39. float t1 = (float)(z + 1) / (data.length - 1); // t1 in [0,1]
  40. for (int x = 0; x < data[z].length; x++) {
  41. // The s texture coordinate for x
  42. float s = (float)x / (data[z].length - 1); // s in [0, 1]
  43. glVertex3f(x, data[z][x], z);
  44. glTexCoord2f(s, t0);
  45. glVertex3f(x, data[z + 1][x], z + 1);
  46. glTexCoord2f(s, t1);
  47. }
  48. glEnd();
  49. }
  50. glEndList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement