master
王宇洋 3 years ago
parent b8346976b6
commit 2999206eb1

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,5 @@
varying vec3 color;
void main() {
gl_FragColor = vec4(color, 1);
}

@ -0,0 +1,6 @@
varying vec3 color;
void main() {
color = gl_Color.rgb;
gl_Position = ftransform();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

@ -10,6 +10,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
/**
* @Author: WangYuyang
* @Date: 2021/11/5-23:09
@ -46,7 +49,8 @@ public class AInterestingVideo extends SceneObject {
getTextures().get("video/video" + counter).bind();
// GL11.glRotatef(90, 0,1,0);;
GL11.glDisable(GL11.GL_LIGHTING); // switch lighting off
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
cube.DrawTexCube();
GL11.glEnable(GL11.GL_LIGHTING); // switch lighting off
;

@ -101,7 +101,8 @@ public class Book extends SceneObject {
Color.white.bind();
glRotatef(yRotation, 0, 1, 0);
getTextures().get("warped_door_bottom").bind();
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL11.glPushMatrix();
{
glRotatef(-45, 1, 0, 0);

@ -10,6 +10,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
/**
* @Author: WangYuyang
* @Date: 2021/11/7-13:40
@ -42,7 +45,8 @@ public class BookShelf extends SceneObject {
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL11.glTranslatef(0, 0, 5);
GL11.glPushMatrix();
{

@ -68,7 +68,8 @@ public class BookTable extends SceneObject {
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL11.glPushMatrix();
{
GL11.glTranslatef(0, scale_number, 0);

@ -5,6 +5,7 @@ import base.GraphicsObjects.Point4f;
import base.GraphicsObjects.Vector4f;
import base.objects3D.BunnyObjTest;
import main.Engine;
import main.ShaderLoader;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
@ -13,6 +14,7 @@ import java.util.HashMap;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.glCallList;
import static org.lwjgl.opengl.GL20.glUseProgram;
/**
* @Author: WangYuyang
@ -99,7 +101,9 @@ public class BunnyTestObject extends SceneObject {
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
GL11.glRotatef(angle + 180, 0, 1, 0);
Color.white.bind();
// glUseProgram(ShaderLoader.shaders.get(0));
glCallList(BunnyObjTest.getBunnyDisplayList());
// glUseProgram(0);
}
@Override
public void drawShadow() {

@ -5,6 +5,7 @@ import base.GraphicsObjects.Point4f;
import base.GraphicsObjects.Vector4f;
import base.objects3D.BunnyObjTest;
import main.Engine;
import main.ShaderLoader;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
@ -13,6 +14,7 @@ import java.util.HashMap;
import java.util.Random;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.glUseProgram;
/**
* @Author: WangYuyang
@ -66,7 +68,9 @@ public class BunnyTestObject2 extends SceneObject {
glTranslatef(0,5f,0);
GL11.glRotatef(angle + 180, 0, 1, 0);
Color.white.bind();
// glUseProgram(ShaderLoader.shaders.get(0));
glCallList(BunnyObjTest.getBunnyDisplayList());
// glUseProgram(0);
GL11.glEnable(GL_TEXTURE_2D);
}
@Override

@ -10,6 +10,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
/**
* @Author: WangYuyang
* @Date: 2021/11/5-23:09
@ -45,7 +48,8 @@ public class Copyleft extends SceneObject {
getTextures().get("copyleft").bind();
;
// GL11.glDisable(GL11.GL_LIGHTING); // switch lighting off
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
cube.DrawTexCube();
// GL11.glEnable(GL11.GL_LIGHTING); // switch lighting off
;

@ -12,6 +12,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
/**
* @Author: WangYuyang
* @Date: 2021/11/5-23:09
@ -53,7 +56,8 @@ public class Cube extends SceneObject {
//bind texture
getTextures().get("debug").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// oval.DrawOval();
cube.DrawTexCube();

@ -12,7 +12,8 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_LINEAR;
/**
* @Author: WangYuyang
@ -48,12 +49,16 @@ public class Ground extends SceneObject {
GL11.GL_REPEAT);
//bind texture
// Color.blue.bind();
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
getTextures().get("wood").bind();
//
// glBindTexture(GL11.GL_TEXTURE_2D, Engine.shadowTexture);
glDisable(GL_LIGHTING);
cube.DrawTexCube();
// glBindTexture(GL11.GL_TEXTURE_2D, 0);
;
glEnable(GL_LIGHTING);
}
@Override

@ -11,6 +11,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
/**
* @Author: WangYuyang
* @Date: 2021/11/2-16:34
@ -34,7 +37,8 @@ public class LAVA_Door extends SceneObject {
Color.white.bind();
getTextures().get("default_lava").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL11.glTranslatef(-2f, 0f, 0);
cube.DrawTexCube();
//LAVA

@ -217,7 +217,8 @@ public class NPC extends SceneObject {
//Enable TEXTURE
//set texture Parameters
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
s1.DrawTexSphere();
//Draw finish Disable TEXTURE
@ -239,7 +240,8 @@ public class NPC extends SceneObject {
getTextures().get("tnt_side").bind(); //set texture
//Enable TEXTURE
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
s2.DrawTexSphere();
; //disable texture

@ -11,6 +11,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
/**
* @Author: WangYuyang
* @Date: 2021/11/2-15:06
@ -33,7 +36,8 @@ public class TNT_Door extends SceneObject {
@Override
public void draw(Integer frame_delta) {
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Color.white.bind();
getTextures().get("tnt_side").bind();
cube1.DrawTexCube();

@ -11,6 +11,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
/**
* @Author: WangYuyang
* @Date: 2021/11/5-23:09
@ -49,7 +52,8 @@ public class VideoTriggerBox extends SceneObject {
//bind texture
getTextures().get("debug").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// oval.DrawOval();
cube.DrawTexCube();

@ -11,6 +11,9 @@ import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
/**
* @Author: WangYuyang
* @Date: 2021/11/2-16:01
@ -46,8 +49,8 @@ public class Wall extends SceneObject {
Color.white.bind();
//bind texture
// getTextures().get("default_dirt").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
MyGrid.DrawTexCube();
;
}

@ -14,13 +14,14 @@ import org.lwjgl.opengl.*;
import org.lwjgl.util.vector.Matrix4f;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.w3c.dom.stylesheets.DocumentStyle;
import java.io.IOException;
import java.nio.FloatBuffer;
import java.util.HashMap;
import java.util.LinkedHashMap;
import static main.Main.camera;
import static main.ShaderLoader.loadShaders;
import static org.lwjgl.opengl.ARBShadowAmbient.GL_TEXTURE_COMPARE_FAIL_VALUE_ARB;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE;
@ -151,6 +152,41 @@ public class Engine {
glClear(GL_COLOR_BUFFER_BIT);
shadowTexture = glGenTextures();
GL11.glMatrixMode(GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 1600, 800, 0, 1, -1);
GL11.glMatrixMode(GL_MODELVIEW);
Texture loading = null;
try {
loading = TextureLoader.getTexture("2021.png", "PNG");
} catch (IOException e) {
e.printStackTrace();
}
Color.white.bind();
loading.bind();
glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_CLAMP);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(1600, 0);
glTexCoord2f(1, 1);
glVertex2i(1600, 800);
glTexCoord2f(0, 1);
glVertex2i(0, 800);
glEnd();
Display.update();
// glEnable(GL_FOG);
// {
@ -165,6 +201,7 @@ public class Engine {
// glFogf(GL_FOG_END, fogFar);
// glFogf(GL_FOG_DENSITY, 0.005f);
// }
loadShaders();
loadTexture();
// setUpFrameBufferObject();

@ -47,6 +47,8 @@ public class Main {
engine.setOrtho(Camera.OrthoNumber);
engine.enterModelView();
engine.initTimer();
// String s;
// s.equalsIgnoreCase()
camera.setCamera(new Vector4f(
@ -90,6 +92,19 @@ public class Main {
key_rotations.add(new Vector4f(0, -180, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 2000));
key_rotations.add(new Vector4f(90, 0, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 2000));
key_rotations.add(new Vector4f(90, 180, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 1000));
key_rotations.add(new Vector4f(90, 180, 45, 1000));
key_positions.add(new Vector4f(0, 7000, 0, 1000));
key_rotations.add(new Vector4f(90, 180, -45, 1000));
key_positions.add(new Vector4f(0, 500, -1000, 4000));
key_rotations.add(new Vector4f(20, 0, 0, 4000));
@ -116,10 +131,10 @@ public class Main {
Vector3f origin_rotation = new Vector3f(Camera.rotation.x, Camera.rotation.y, Camera.rotation.z);
Vector4f Current_position = Camera.position;
Vector3f Current_rotation = Camera.rotation;
System.out.println("Current_position: " + Current_position);
System.out.println("Current_rotation: " + Current_rotation);
System.out.println("key_position: " + key_position);
System.out.println("key_rotation: " + key_rotation);
// System.out.println("Current_position: " + Current_position);
// System.out.println("Current_rotation: " + Current_rotation);
// System.out.println("key_position: " + key_position);
// System.out.println("key_rotation: " + key_rotation);
float position_x_distance = key_position.x - Current_position.x;
float position_y_distance = key_position.y - Current_position.y;
float position_z_distance = key_position.z - Current_position.z;
@ -132,12 +147,12 @@ public class Main {
float rotation_x_distance_step = rotation_x_distance / key_position.a;
float rotation_y_distance_step = rotation_y_distance / key_position.a;
float rotation_z_distance_step = rotation_z_distance / key_position.a;
System.out.println("position_x_distance_step: " + position_x_distance_step);
System.out.println("position_y_distance_step: " + position_y_distance_step);
System.out.println("position_z_distance_step: " + position_z_distance_step);
System.out.println("rotation_x_distance_step: " + rotation_x_distance_step);
System.out.println("rotation_y_distance_step: " + rotation_y_distance_step);
System.out.println("rotation_z_distance_step: " + rotation_z_distance_step);
// System.out.println("position_x_distance_step: " + position_x_distance_step);
// System.out.println("position_y_distance_step: " + position_y_distance_step);
// System.out.println("position_z_distance_step: " + position_z_distance_step);
// System.out.println("rotation_x_distance_step: " + rotation_x_distance_step);
// System.out.println("rotation_y_distance_step: " + rotation_y_distance_step);
// System.out.println("rotation_z_distance_step: " + rotation_z_distance_step);
float count = 0f;
while (count < key_position.a) {
@ -158,13 +173,13 @@ public class Main {
e.printStackTrace();
}
}
System.out.println(Current_position);
System.out.println(Current_rotation);
// System.out.println(Current_position);
// System.out.println(Current_rotation);
Current_position = key_position;
Current_rotation = new Vector3f(key_rotation.x, key_rotation.y, key_rotation.z);
System.out.println(Current_position);
System.out.println(Current_rotation);
System.out.println("-------------------------------------------------");
// System.out.println(Current_position);
// System.out.println(Current_rotation);
// System.out.println("-------------------------------------------------");
}
Camera.loading_finished = true;
}

@ -0,0 +1,97 @@
package main;
import org.lwjgl.opengl.Display;
import org.newdawn.slick.util.ResourceLoader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import static org.lwjgl.opengl.GL11.GL_FALSE;
import static org.lwjgl.opengl.GL20.*;
/**
* @Author: WangYuyang
* @Date: 2021/11/18-16:57
* @Project: Assignment3
* @Package: main
* @Description:
**/
public class ShaderLoader {
public static HashMap<Integer, Integer> shaders = new LinkedHashMap<>();
public static void loadShaders() {
loadShader(0, "shader.vs", "shader.fs");
System.out.println("Shaders load ok.");
}
private static void loadShader(Integer id, String filename_vs, String filename_fs) {
int shaderProgram = glCreateProgram();
int vertexShader = glCreateShader(GL_VERTEX_SHADER);
int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
StringBuilder vertexShaderSource = new StringBuilder();
StringBuilder fragmentShaderSource = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("res/shaders/" + filename_vs));
String line;
while ((line = reader.readLine()) != null) {
vertexShaderSource.append(line).append('\n');
}
} catch (IOException e) {
System.err.println("Vertex shader wasn't loaded properly.");
e.printStackTrace();
Display.destroy();
System.exit(1);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedReader reader2 = null;
try {
reader2 = new BufferedReader(new FileReader("res/shaders/" + filename_fs));
String line;
while ((line = reader2.readLine()) != null) {
fragmentShaderSource.append(line).append('\n');
}
} catch (IOException e) {
System.err.println("Fragment shader wasn't loaded properly.");
Display.destroy();
System.exit(1);
} finally {
if (reader2 != null) {
try {
reader2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
glShaderSource(vertexShader, vertexShaderSource);
glCompileShader(vertexShader);
if (glGetShaderi(vertexShader, GL_COMPILE_STATUS) == GL_FALSE) {
System.err.println("Vertex shader wasn't able to be compiled correctly.");
}
glShaderSource(fragmentShader, fragmentShaderSource);
glCompileShader(fragmentShader);
if (glGetShaderi(fragmentShader, GL_COMPILE_STATUS) == GL_FALSE) {
System.err.println("Fragment shader wasn't able to be compiled correctly.");
}
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glValidateProgram(shaderProgram);
System.out.println("Id: " + shaderProgram + " <> ValidateProgram finish.");
shaders.put(id, shaderProgram);
}
}

@ -78,4 +78,9 @@ public class TextureLoader {
org.newdawn.slick.opengl.TextureLoader.getTexture(fileType, ResourceLoader.getResourceAsStream("res/" + filename))
);
}
public static Texture getTexture(String filename, String fileType) throws IOException {
String key_name = filename.split("\\.")[0];
return org.newdawn.slick.opengl.TextureLoader.getTexture(fileType, ResourceLoader.getResourceAsStream("res/" + filename));
}
}

Loading…
Cancel
Save