Permalink
Browse files

old uneeded files, replaced in position

  • Loading branch information...
1 parent 030ab75 commit f06f6289e99e7a48603dba6e891adebf0b8995df @alihelmy committed Sep 24, 2011
@@ -1,84 +0,0 @@
-package com.onehandstand.lwjgltutorial.lessonone;
-
-import java.util.ArrayList;
-
-import org.lwjgl.LWJGLException;
-import org.lwjgl.opengl.Display;
-import org.lwjgl.opengl.DisplayMode;
-/* using java static import give makes code similar to
- * C/C++, calling gl functions and GL_ constants directly
- */
-import static org.lwjgl.opengl.GL11.*;
-import org.lwjgl.util.glu.GLU;
-
-public class LessonOne {
-
- private ShaderTriangle triangle;
-
- public void start() {
- try {
- DisplayMode displayMode = new DisplayMode(1280, 800);
- Display.setDisplayMode(displayMode);
- Display.setVSyncEnabled(true);
- Display.setTitle("Modern OpenGL LWJGL Port Lesson One");
- 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();
- }
-
- 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, 0.1f, 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);
- }
-
- public static void main(String[] args) {
- LessonOne lessonOne = new LessonOne();
- lessonOne.start();
- }
-
-}
@@ -1,139 +0,0 @@
-package com.onehandstand.lwjgltutorial.lessonone;
-
-import static org.lwjgl.opengl.ARBShaderObjects.*;
-
-import java.io.BufferedReader;
-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;
-import static org.lwjgl.opengl.GL11.*;
-
-public class ShaderTriangle {
-
- private int shader, vertexShader, fragmentShader;
- private boolean useShaders;
-
- public static boolean verboseValidityCheck=false;
- private static final String SHADERS_ROOT_PATH="shaders";
-
- public ShaderTriangle() {
- this.shader=0;
- this.vertexShader=0;
- this.fragmentShader=0;
- this.useShaders=false;
- this.initShaders();
- }
-
- private void initShaders() {
- //create the main shader program
- this.shader=glCreateProgramObjectARB();
- if(this.shader!=0) { //if passed, create sub shaders
- this.vertexShader=createVertexShader(SHADERS_ROOT_PATH+"/screen.vert");
- this.fragmentShader=createFragmentShader(SHADERS_ROOT_PATH+"/screen.frag");
- if(this.vertexShader!=0 && this.fragmentShader!=0) {
- //add in shaders to main program
- glAttachObjectARB(this.shader, this.vertexShader);
- glAttachObjectARB(this.shader, this.vertexShader);
- glLinkProgramARB(this.shader);
- glValidateProgramARB(this.shader);
- //check if shader is valid
- if(this.isShaderValid(this.shader)) {
- this.useShaders=true;
- }
- }
- }
- }
-
- public void draw() {
- if(useShaders) { //use the shader linked
- glUseProgramObjectARB(this.shader);
- }
-
- // normal rendering code
- glLoadIdentity();
- //white, which will show if our fragment shader doesn't work
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glBegin(GL_TRIANGLES);
- glVertex2f(0.0f, 0.8f);
- glVertex2f(-0.8f, -0.8f);
- glVertex2f(0.8f, -0.8f);
- glEnd();
-
- //free up use of shader program
- glUseProgramObjectARB(0);
- }
-
- private int createFragmentShader(String pathToShaderFile) {
- int fragmentShader=createShader(pathToShaderFile, ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
- return fragmentShader;
- }
-
- private int createVertexShader(String pathToShaderFile) {
- int vertexShader=createShader(pathToShaderFile, ARBVertexShader.GL_VERTEX_SHADER_ARB);
- return vertexShader;
- }
-
- private int createShader(String pathToShaderFile, int shaderType) {
- int newShader=glCreateShaderObjectARB(shaderType);
- if(newShader!=0) {
- String shaderCode=readInShaderCodeFromShaderFile(pathToShaderFile);
- 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 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);
- codeLine=bufferedReader.readLine();
- }
- return shaderCodeBuffer.toString();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- private 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 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);
- }
-
-}
@@ -1,6 +0,0 @@
-#version 120
-void main(void) {
- gl_FragColor[0] = 0.0;
- gl_FragColor[1] = 0.0;
- gl_FragColor[2] = 1.0;
-}
@@ -1,5 +0,0 @@
-#version 120
-attribute vec2 coord2d;
-void main(void) {
- gl_Position = vec4(coord2d, 0.0, 1.0);
-}

0 comments on commit f06f628

Please sign in to comment.