Advertisement
Guest User

Untitled

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