Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. package ecumene.opengl;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4. import org.lwjgl.util.vector.Vector2f;
  5. import org.lwjgl.util.vector.Vector3f;
  6. import org.lwjgl.util.vector.Vector4f;
  7.  
  8. import ecumene.data.Color;
  9.  
  10. /**
  11. * Contains data to be processed per-vertex, like color,
  12. * position, texture coordinates, and normals
  13. *
  14. * @author Ecumene
  15. */
  16. public class Vertex {
  17. /**The vertex's location*/
  18. public Vector4f position;
  19. /**The vertex's uv*/
  20. public Vector2f textureUV;
  21. /**The vertex's color*/
  22. public Color color;
  23. /**The vertex's normal*/
  24. public Vector3f normal;
  25.  
  26. /**
  27. * Initializes the vertex with all possible information
  28. *
  29. * @param position The vertex's position
  30. * @param textureUV The vertex's texture coordinate
  31. * @param normal The vertex's normal
  32. * @param color The vertex's color
  33. */
  34. public Vertex(Vector4f position, Vector2f textureUV, Color color, Vector3f normal){
  35. this.position = position;
  36. this.textureUV = textureUV;
  37. this.color = color;
  38. this.normal = normal;
  39. }
  40.  
  41. /**
  42. * Initializes the vertex with no normal
  43. *
  44. * @param position The vertex's position
  45. * @param textureUV The vertex's texture coordinate
  46. * @param color The vertex's color
  47. */
  48. public Vertex(Vector4f position, Vector2f textureUV, Color color){
  49. this(position, textureUV, color, new Vector3f(0, 0, 0));
  50. }
  51.  
  52. /**
  53. * Initializes the vertex with no normal, or texture coordinate
  54. *
  55. * @param position The vertex's position
  56. * @param color The vertex's color
  57. */
  58. public Vertex(Vector4f position, Color color){
  59. this(position, new Vector2f(0, 0), color, new Vector3f(0, 0, 0));
  60. }
  61.  
  62. /**
  63. * Initializes the vertex with no normal, color, or texture coordinate,
  64. * just a position.
  65. *
  66. * @param position The vertex's position
  67. */
  68. public Vertex(Vector4f position){
  69. this(position, new Vector2f(0, 0), new Color(1, 1, 1, 1), new Vector3f(0, 0, 0));
  70. }
  71.  
  72. /**
  73. * Draws the vertex using OpenGL 1.0
  74. * @deprecated Because OpenGL 1.0 is very old
  75. */
  76. @Deprecated
  77. public static void draw(Vertex vert){
  78. GL11.glVertex4f(vert.position.x, vert.position.y, vert.position.z, vert.position.w);
  79. GL11.glColor4f(vert.color.getRed(), vert.color.getGreen(), vert.color.getBlue(), vert.color.getAlpha());
  80. GL11.glNormal3f(vert.normal.x, vert.normal.y, vert.normal.z);
  81. GL11.glTexCoord2f(vert.textureUV.x, vert.textureUV.y);
  82. }
  83.  
  84. /**
  85. * Draws the vertex using OpenGL 1.0
  86. * @deprecated Because OpenGL 1.0 is very old
  87. */
  88. @Deprecated
  89. public void draw(){
  90. GL11.glVertex4f(position.x, position.y, position.z, position.w);
  91. GL11.glColor4f(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
  92. GL11.glNormal3f(normal.x, normal.y, normal.z);
  93. GL11.glTexCoord2f(textureUV.x, textureUV.y);
  94. }
  95.  
  96. /**
  97. * Draws the given vertices using OpenGL 1.0
  98. * @deprecated Because OpenGL 1.0 is very old
  99. */
  100. @Deprecated
  101. public static void drawAll(Vertex[] model, int mode){
  102. GL11.glBegin(mode);
  103. for(Vertex vert : model){
  104. GL11.glVertex4f(vert.position.x, vert.position.y, vert.position.z, vert.position.w);
  105. GL11.glColor4f(vert.color.getRed(), vert.color.getGreen(), vert.color.getBlue(), vert.color.getAlpha());
  106. GL11.glNormal3f(vert.normal.x, vert.normal.y, vert.normal.z);
  107. GL11.glTexCoord2f(vert.textureUV.x, vert.textureUV.y);
  108. }
  109. GL11.glEnd();
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement