Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. import org.lwjgl.BufferUtils;
  2. import org.lwjgl.opengl.GL;
  3. import java.nio.ByteBuffer;
  4. import java.nio.IntBuffer;
  5. import java.util.TimeZone;
  6.  
  7. import static org.lwjgl.glfw.GLFW.*;
  8. import static org.lwjgl.opengl.GL11.*;
  9. import static org.lwjgl.stb.STBImage.stbi_image_free;
  10. import static org.lwjgl.stb.STBImage.stbi_load;
  11.  
  12.  
  13. import java.util.Calendar;
  14.  
  15.  
  16.  
  17. public class Desafio02teste{
  18.  
  19. int SCREEN_WIDTH = 640;
  20. int SCREEN_HEIGHT = 480;
  21. int SCREEN_FPS = 60;
  22.  
  23. private static float mTextureWidth;
  24. private static float mTextureHeight;
  25. private static int id;
  26.  
  27.  
  28. public Desafio02teste(){
  29.  
  30. if (!glfwInit()) {
  31. System.err.println("Falha ao inicializar GLFW!");
  32. System.exit(1);
  33. }
  34.  
  35. long win = glfwCreateWindow(940, 940, "Window", 0, 0);
  36.  
  37. glfwShowWindow(win);
  38. glfwMakeContextCurrent(win);
  39. GL.createCapabilities();
  40. glEnable(GL_TEXTURE_2D);
  41.  
  42.  
  43. while (!glfwWindowShouldClose(win)) {
  44.  
  45. Calendar cal = Calendar.getInstance();
  46. cal.setTimeZone(TimeZone.getTimeZone("GMT-03:00"));
  47. int hours = cal.get(Calendar.HOUR_OF_DAY);
  48. int minutes = cal.get(Calendar.MINUTE);
  49. int seconds = cal.get(Calendar.SECOND);
  50. int millisecond = cal.get(Calendar.MILLISECOND);
  51.  
  52. glfwPollEvents();
  53. glClear(GL_COLOR_BUFFER_BIT);
  54.  
  55.  
  56. IntBuffer width = BufferUtils.createIntBuffer(1);
  57. IntBuffer height = BufferUtils.createIntBuffer(1);
  58. IntBuffer comp = BufferUtils.createIntBuffer(1);
  59. ByteBuffer data = stbi_load("res/clockimg.png" , width, height, comp, 4);
  60. id = glGenTextures();
  61. glBindTexture(GL_TEXTURE_2D, id);
  62. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  63. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  64. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.get(), height.get(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
  65. stbi_image_free(data);
  66. mTextureWidth = width.get(0);
  67. mTextureHeight = height.get(0);
  68.  
  69. glColor3f(1.0f, 1.0f, 1.0f);
  70. glBindTexture(GL_TEXTURE_2D, id);
  71. glBegin(GL_QUADS);
  72. glTexCoord2f(0,0);
  73. glVertex2f(-0.2f, 0.2f);
  74. glTexCoord2f(1,0);
  75. glVertex2f(0.2f, 0.2f);
  76. glTexCoord2f(1,1);
  77. glVertex2f(0.2f, -0.2f);
  78. glTexCoord2f(0,1);
  79. glVertex2f(-0.2f, -0.2f);
  80. glEnd();
  81.  
  82.  
  83.  
  84. glPushMatrix();
  85. glRotatef(-hours * 30, 0.f, 0.f, 0.f);
  86. glBegin(GL_LINES);
  87. glColor3f( 0.f, 0.f, 0.f);
  88. glVertex2f(0,0);
  89. glVertex2f(0, 0.5f);
  90. glEnd();
  91. glPopMatrix();
  92.  
  93.  
  94. glfwSwapBuffers(win);
  95.  
  96. }
  97. glfwTerminate();
  98. }
  99.  
  100. public static void main(String[] args) {
  101. new Desafio02teste();
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement