package org engine import org lwjgl LWJGLException import org lwjgl op

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package org.engine;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class GLEngine {
private int width; // ширина окна
private int height; // высота окна
private String title; // заголовок окна
private Texture texture;
private int rotate = 1;
private float rotateX = 0.0f;
private void loadTexture() {
}
public GLEngine(String title, int width, int height, int x, int y) throws FileNotFoundException, IOException { // конструктор класса
this.width = width;
this.height = height;
this.title = title;
this.x = x;
this.y = y;
texture = TextureLoader.getTexture("JPG", new FileInputStream(new File("/Users/nikita/IdeaProjects/OpenGLLab1/stones.jpg")));
}
private void initGL() throws LWJGLException {
Display.setDisplayMode(new DisplayMode(width, height)); // задаём размер экрана
Display.setTitle(title); // задаём заголовок экрана
Display.create(); // создаём окно с заданным форматом пикселей
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
GL11.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
GL11.glDepthFunc(GL11.GL_LESS); // The Type Of Depth Test To Do
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
GL11.glShadeModel(GL11.GL_SMOOTH); // Enables Smooth Color Shading
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity(); // Reset The Projection Matrix
GLU.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
public void start() throws LWJGLException {
initGL();
while (!Display.isCloseRequested()) { // пока окно не закрыто
render(); // рисуем
Display.update(); // обновляем экран
Display.sync(60);
}
Display.destroy(); // уничтожаем окно
}
public void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // устанавливаем буферизацию для окна
GL11.glLoadIdentity(); // Reset The View
GL11.glTranslatef(0f, 0.0f, -8f);
GL11.glRotatef(rotateX, -5.0f, 1.0f, 0.0f);
GL11.glColor3f(0.5f, 0.5f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(1.0f, 1.0f, 0.0f);
GL11.glVertex3f(1.0f, 1.0f, -1.0f);
GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
GL11.glVertex3f(1.0f, 1.0f, 1.0f);
GL11.glColor3f(1.0f, 0.5f, 0.0f);
GL11.glVertex3f(1.0f, -1.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
GL11.glVertex3f(1.0f, -1.0f, -1.0f);
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
GL11.glVertex3f(1.0f, -1.0f, 1.0f);
GL11.glColor3f(1.0f, 1.0f, 0.0f);
GL11.glVertex3f(1.0f, -1.0f, -1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
GL11.glVertex3f(1.0f, 1.0f, -1.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
GL11.glColor3f(1.0f, 0.0f, 1.0f);
GL11.glVertex3f(1.0f, 1.0f, -1.0f);
GL11.glVertex3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f(1.0f, -1.0f, 1.0f);
GL11.glVertex3f(1.0f, -1.0f, -1.0f);
GL11.glEnd();
rotateX += 5.0f;
}
}