Permalink
Browse files

added in lesson2 eclipse structure

  • Loading branch information...
1 parent e2bccf0 commit 0e3a07f4ecbe8a679659c7e902bfe272085d09ba @alihelmy committed Apr 22, 2012
Showing with 940 additions and 11 deletions.
  1. +17 −0 .metadata/.log
  2. +95 −0 .metadata/.plugins/org.eclipse.core.resources/.history/17/700c2efc898c00111f1581251e4956b9
  3. +5 −0 .metadata/.plugins/org.eclipse.core.resources/.history/1c/809bca70898c00111f1581251e4956b9
  4. +106 −0 .metadata/.plugins/org.eclipse.core.resources/.history/25/305948cb898c00111f1581251e4956b9
  5. +94 −0 .metadata/.plugins/org.eclipse.core.resources/.history/33/503646cb898c00111f1581251e4956b9
  6. 0 ...java → .metadata/.plugins/org.eclipse.core.resources/.history/55/0088cebe898c00111f1581251e4956b9
  7. 0 ...java → .metadata/.plugins/org.eclipse.core.resources/.history/63/c03110b9898c00111f1581251e4956b9
  8. +7 −0 .metadata/.plugins/org.eclipse.core.resources/.history/88/009f3073898c00111f1581251e4956b9
  9. +133 −0 .metadata/.plugins/org.eclipse.core.resources/.history/9d/30ca4acb898c00111f1581251e4956b9
  10. +94 −0 .metadata/.plugins/org.eclipse.core.resources/.history/cd/7042baf8898c00111f1581251e4956b9
  11. 0 ...java → .metadata/.plugins/org.eclipse.core.resources/.history/d1/b029debc898c00111f1581251e4956b9
  12. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonOne/.indexes/2e/history.index
  13. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonOne/.markers.snap
  14. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonOne/.syncinfo.snap
  15. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonTwo/.indexes/3e/f4/history.index
  16. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonTwo/.indexes/81/df/3e/14/history.index
  17. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonTwo/.markers.snap
  18. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/LessonTwo/.syncinfo.snap
  19. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/libs/.markers.snap
  20. BIN .metadata/.plugins/org.eclipse.core.resources/.projects/libs/.syncinfo.snap
  21. BIN .metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap
  22. BIN .metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
  23. BIN .metadata/.plugins/org.eclipse.core.resources/.snap
  24. +2 −0 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
  25. +2 −0 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs
  26. +0 −1 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs
  27. +2 −0 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs
  28. +11 −0 .metadata/.plugins/org.eclipse.debug.core/.launches/LessonTwo.launch
  29. BIN .metadata/.plugins/org.eclipse.jdt.core/2791608477.index
  30. +1 −10 .metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt
  31. BIN .metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat
  32. BIN .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png
  33. BIN .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png
  34. BIN .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png
  35. +4 −0 .../.plugins/org.eclipse.ltk.core.refactoring/.refactorings/LessonTwo/2012/4/16/refactorings.history
  36. +1 −0 ...ta/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/LessonTwo/2012/4/16/refactorings.index
  37. +16 −0 LessonTwo/.classpath
  38. +17 −0 LessonTwo/.project
  39. +106 −0 LessonTwo/lwjgltutorial/lessonTwo/Main.java
  40. +133 −0 LessonTwo/lwjgltutorial/lessonTwo/ShaderTriangle.java
  41. +94 −0 LessonTwo/lwjgltutorial/lessonTwo/ShaderUtilities.java
View
@@ -8,3 +8,20 @@ Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.e
!ENTRY org.eclipse.core.resources 2 10035 2012-04-22 16:28:51.949
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+
+!ENTRY org.eclipse.jdt.ui 4 10001 2012-04-22 16:46:57.956
+!MESSAGE Internal Error
+!STACK 1
+Java Model Exception: Java Model Status [Timed out while retrieving the attached javadoc for BufferedReader [in BufferedReader.class [in java.io [in C:\Program Files\Java\jre6\lib\rt.jar]]] ]
+ at org.eclipse.jdt.internal.core.JavaElement.getURLContents(JavaElement.java:808)
+ at org.eclipse.jdt.internal.core.BinaryType.getJavadocContents(BinaryType.java:1037)
+ at org.eclipse.jdt.internal.core.BinaryMethod.getAttachedJavadoc(BinaryMethod.java:643)
+ at org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2.getHTMLContent(JavadocContentAccess2.java:465)
+ at org.eclipse.jdt.internal.ui.text.java.ProposalInfo.extractJavadoc(ProposalInfo.java:95)
+ at org.eclipse.jdt.internal.ui.text.java.ProposalInfo.computeInfo(ProposalInfo.java:75)
+ at org.eclipse.jdt.internal.ui.text.java.ProposalInfo.getInfo(ProposalInfo.java:58)
+ at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.getAdditionalProposalInfo(AbstractJavaCompletionProposal.java:555)
+ at org.eclipse.jface.text.contentassist.AdditionalInfoController$3.run(AdditionalInfoController.java:106)
+ at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
+!SUBENTRY 1 org.eclipse.jdt.core 4 1012 2012-04-22 16:46:57.957
+!MESSAGE Timed out while retrieving the attached javadoc for BufferedReader [in BufferedReader.class [in java.io [in C:\Program Files\Java\jre6\lib\rt.jar]]]
@@ -0,0 +1,95 @@
+package lwjgltutorial.lessonTwo;
+
+import static org.lwjgl.opengl.ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glCompileShaderARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glCreateShaderObjectARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glGetInfoLogARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glGetObjectParameterARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glShaderSourceARB;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.opengl.ARBFragmentShader;
+import org.lwjgl.opengl.ARBVertexShader;
+
+public class ShaderUtilities {
+
+ private static boolean verboseValidityCheck=false;
+ private static final String SHADERS_ROOT_PATH="shaders";
+
+ public static int createFragmentShader(String pathToShaderFile) {
+ int fragmentShader=createShader(pathToShaderFile, ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
+ return fragmentShader;
+ }
+
+ public static int createVertexShader(String pathToShaderFile) {
+ int vertexShader=createShader(pathToShaderFile, ARBVertexShader.GL_VERTEX_SHADER_ARB);
+ return vertexShader;
+ }
+
+ public static int createShader(String shaderFileName, int shaderType) {
+ String shaderFilePath=SHADERS_ROOT_PATH+File.separator+shaderFileName;
+ int newShader=glCreateShaderObjectARB(shaderType);
+ if(newShader!=0) {
+ String shaderCode=readInShaderCodeFromShaderFile(shaderFilePath);
+ if(shaderCode!=null && !shaderCode.isEmpty()) {
+ glShaderSourceARB(newShader, shaderCode);
+ glCompileShaderARB(newShader);
+ if(isShaderValid(newShader)) {
+ return newShader;
+ }
+ }
+ }
+ //if anything fails, return 0 as error code
+ return 0;
+ }
+
+ private static String readInShaderCodeFromShaderFile(String pathToShaderFile) {
+ try {
+ BufferedReader bufferedReader=new BufferedReader(new FileReader(pathToShaderFile));
+ StringBuffer shaderCodeBuffer=new StringBuffer();
+ String codeLine=bufferedReader.readLine();
+ while(codeLine!=null) {
+ shaderCodeBuffer.append(codeLine+"\n");
+ codeLine=bufferedReader.readLine();
+ }
+ bufferedReader.close();
+ return shaderCodeBuffer.toString();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static boolean isShaderValid(int shaderToCheck) {
+ IntBuffer iVal = BufferUtils.createIntBuffer(1);
+ glGetObjectParameterARB(shaderToCheck, GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
+ int length = iVal.get();
+ boolean isValid = length>1;
+
+ if (isValid && verboseValidityCheck) {
+ printShaderLogInfo(shaderToCheck, iVal, length);
+ }
+
+ return isValid;
+ }
+
+ private static void printShaderLogInfo(int shaderToCheck, IntBuffer iVal,
+ int length) {
+ ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
+ iVal.flip();
+ glGetInfoLogARB(shaderToCheck, iVal, infoLog);
+ byte[] infoBytes = new byte[length];
+ infoLog.get(infoBytes);
+ String out = new String(infoBytes);
+ System.out.println("Info log:\n"+out);
+ }
+
+}
@@ -0,0 +1,5 @@
+#version 120
+attribute vec2 coord2d;
+void main(void) {
+ gl_Position = vec4(coord2d, 0.0, 1.0);
+}
@@ -0,0 +1,106 @@
+package lwjgltutorial.lessonTwo;
+
+import static org.lwjgl.opengl.GL11.GL_BLEND;
+import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
+import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
+import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
+import static org.lwjgl.opengl.GL11.GL_LEQUAL;
+import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
+import static org.lwjgl.opengl.GL11.GL_NICEST;
+import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
+import static org.lwjgl.opengl.GL11.GL_PERSPECTIVE_CORRECTION_HINT;
+import static org.lwjgl.opengl.GL11.GL_PROJECTION;
+import static org.lwjgl.opengl.GL11.GL_SMOOTH;
+import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
+import static org.lwjgl.opengl.GL11.glBlendFunc;
+import static org.lwjgl.opengl.GL11.glClear;
+import static org.lwjgl.opengl.GL11.glClearColor;
+import static org.lwjgl.opengl.GL11.glClearDepth;
+import static org.lwjgl.opengl.GL11.glDepthFunc;
+import static org.lwjgl.opengl.GL11.glEnable;
+import static org.lwjgl.opengl.GL11.glHint;
+import static org.lwjgl.opengl.GL11.glLoadIdentity;
+import static org.lwjgl.opengl.GL11.glMatrixMode;
+import static org.lwjgl.opengl.GL11.glShadeModel;
+import static org.lwjgl.opengl.GL11.glViewport;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.DisplayMode;
+import org.lwjgl.util.glu.GLU;
+
+public class Main {
+
+ private ShaderTriangle triangle;
+
+ public void start() {
+ try {
+ DisplayMode displayMode = new DisplayMode(640, 480);
+ Display.setDisplayMode(displayMode);
+ Display.setVSyncEnabled(true);
+ Display.setTitle("Modern OpenGL LWJGL Port Lesson Two");
+ Display.create();
+ } catch (LWJGLException exception) {
+ exception.printStackTrace();
+ System.exit(0);
+ }
+
+ this.init();
+
+ // main loop
+ while (!Display.isCloseRequested()) {
+ this.render();
+ Display.update();
+ }
+
+ // close down
+ Display.destroy();
+ System.exit(0);
+ }
+
+ private void init() {
+ this.initOpenGL();
+ this.initWorld();
+ }
+
+ private void initWorld() {
+ this.triangle=new ShaderTriangle();
+ }
+
+ private void render() {
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ //world rendering code
+ this.triangle.draw();
+ }
+
+ private void initOpenGL() {
+ // setup viewing area
+ DisplayMode displayMode = Display.getDisplayMode();
+ int width = displayMode.getWidth();
+ int height = displayMode.getHeight();
+ glViewport(0, 0, width, height);
+ // setup the camera params
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ GLU.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100f);
+ // setup the model (drawing) params
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glShadeModel(GL_SMOOTH);
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // white
+ glClearDepth(1.0f);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ //enable blending
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ public static void main(String[] args) {
+ Main lessonOne = new Main();
+ lessonOne.start();
+ }
+
+}
@@ -0,0 +1,94 @@
+package lwjgltutorial.lessonTwo;
+
+import static org.lwjgl.opengl.ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glCompileShaderARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glCreateShaderObjectARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glGetInfoLogARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glGetObjectParameterARB;
+import static org.lwjgl.opengl.ARBShaderObjects.glShaderSourceARB;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.opengl.ARBFragmentShader;
+import org.lwjgl.opengl.ARBVertexShader;
+
+public class ShaderUtilities {
+
+ private static boolean verboseValidityCheck=false;
+ private static final String SHADERS_ROOT_PATH="shaders";
+
+ public static int createFragmentShader(String pathToShaderFile) {
+ int fragmentShader=createShader(pathToShaderFile, ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
+ return fragmentShader;
+ }
+
+ public static int createVertexShader(String pathToShaderFile) {
+ int vertexShader=createShader(pathToShaderFile, ARBVertexShader.GL_VERTEX_SHADER_ARB);
+ return vertexShader;
+ }
+
+ public static int createShader(String shaderFileName, int shaderType) {
+ String shaderFilePath=SHADERS_ROOT_PATH+File.separator+shaderFileName;
+ int newShader=glCreateShaderObjectARB(shaderType);
+ if(newShader!=0) {
+ String shaderCode=readInShaderCodeFromShaderFile(shaderFilePath);
+ if(shaderCode!=null && !shaderCode.isEmpty()) {
+ glShaderSourceARB(newShader, shaderCode);
+ glCompileShaderARB(newShader);
+ if(isShaderValid(newShader)) {
+ return newShader;
+ }
+ }
+ }
+ //if anything fails, return 0 as error code
+ return 0;
+ }
+
+ private static String readInShaderCodeFromShaderFile(String pathToShaderFile) {
+ try {
+ BufferedReader bufferedReader=new BufferedReader(new FileReader(pathToShaderFile));
+ StringBuffer shaderCodeBuffer=new StringBuffer();
+ String codeLine=bufferedReader.readLine();
+ while(codeLine!=null) {
+ shaderCodeBuffer.append(codeLine+"\n");
+ codeLine=bufferedReader.readLine();
+ }
+ return shaderCodeBuffer.toString();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static boolean isShaderValid(int shaderToCheck) {
+ IntBuffer iVal = BufferUtils.createIntBuffer(1);
+ glGetObjectParameterARB(shaderToCheck, GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
+ int length = iVal.get();
+ boolean isValid = length>1;
+
+ if (isValid && verboseValidityCheck) {
+ printShaderLogInfo(shaderToCheck, iVal, length);
+ }
+
+ return isValid;
+ }
+
+ private static void printShaderLogInfo(int shaderToCheck, IntBuffer iVal,
+ int length) {
+ ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
+ iVal.flip();
+ glGetInfoLogARB(shaderToCheck, iVal, infoLog);
+ byte[] infoBytes = new byte[length];
+ infoLog.get(infoBytes);
+ String out = new String(infoBytes);
+ System.out.println("Info log:\n"+out);
+ }
+
+}
@@ -0,0 +1,7 @@
+#version 120
+
+attribute vec2 coord2d;
+
+void main(void) {
+ gl_Position = vec4(coord2d, 0.0, 1.0);
+}
Oops, something went wrong. Retry.

0 comments on commit 0e3a07f

Please sign in to comment.