Skip to content

Instantly share code, notes, and snippets.

@kaosine
Created September 29, 2017 18:01
Show Gist options
  • Save kaosine/2a7417033b08cc16db1f86fcff1af627 to your computer and use it in GitHub Desktop.
Save kaosine/2a7417033b08cc16db1f86fcff1af627 to your computer and use it in GitHub Desktop.
New Main
import org.lwjgl.glfw.GLFWVidMode;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.GL;
public class Main {
public Main(){
// test glfw initialization
if (!glfwInit()){
System.err.println("GLFW Failed to initialize");
System.exit(1);
}
//create the window
long window = glfwCreateWindow(640, 480, "LWJGL Tutorial", 0, 0);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
if (window == 0){
System.err.println("Failed to create the Window");
}
// set video mode, and show the window with capabilities for GL
GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidMode.width() - 640)/2, (vidMode.height() - 480) /2 );
glfwShowWindow(window);
glfwMakeContextCurrent(window);
GL.createCapabilities();
// set the background color
glClearColor(0.16f, 0.16f, 0.2f, 1f);
float x = 0;
float count = 0;
float red_color = 1;
float blue_color = 0;
float green_color = 0;
// Game loop
while(!glfwWindowShouldClose(window)){
glfwPollEvents();
if (glfwGetKey(window, GLFW_KEY_A) == GL_TRUE){
x+= 0.001f;
} else if (glfwGetKey(window, GLFW_KEY_D) == GL_TRUE){
x-= 0.001f;
}
//set the color
glClear(GL_COLOR_BUFFER_BIT);
// don't use for real, just for testing. Shows a simple square
glBegin(GL_QUADS);
glColor4f(red_color, green_color, blue_color, 0f);
glVertex2f(-0.5f + x,0.5f);
glVertex2f(0.5f + x,0.5f);
glVertex2f(0.5f + x,-0.5f);
glVertex2f(-0.5f + x,-0.5f);
glEnd(); // must end the draw mode
glfwSwapBuffers(window); // show the updates
}
glfwTerminate(); // clean up
}
public static void main(String[] args){
new Main(); // call and start the game
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment