2017-05-31 1 views
0

Je suis nouveau sur LWJGL et OpenGL, et j'ai fait quelques recherches sur google et je n'ai pas trouvé d'autre chose à ce sujet. J'ai fait un programme de test de base pour créer une fenêtre vide. Je peux créer la fenêtre et exécuter l'application bien, mais si j'essaie de changer la couleur claire en utilisant glClearColor(), l'application "se bloque".L'appel de la fonction "glClearColor()" provoque une vidage mémoire

Voici le texte imprimé dans la console:

[error occurred during error reporting (printing problematic frame), id 0xe0000000] 
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again 
# 
# An error report file with more information is saved as: 
# /*****/*******/eclipse/java-neon/workspace/LWJGL Project/hs_err_pid10749.log 
# 
# If you would like to submit a bug report, please visit: 
# http://bugreport.java.com/bugreport/crash.jsp 
# The crash happened outside the Java Virtual Machine in native code. 
# See problematic frame for where to report the bug. 
# 

Ceci est le fichier que l'erreur créée (assez grand): https://pastebin.com/9h0gsRmTlink

Voici le code:

package me.smorce.project; 

import static org.lwjgl.glfw.GLFW.*; 
import static org.lwjgl.opengl.GL11.*; 
import static org.lwjgl.system.MemoryUtil.*; 
import org.lwjgl.glfw.GLFWVidMode; 
import me.smorce.project.input.Input; 

public class Game 
{ 
    public boolean running = false; 
    private long window; 
    public int windowWidth = 1280; 
    public int windowHeight = windowWidth/16 * 9; 

    public void start() 
    { 
     running = true; 
     init(); 
     while(running) 
     { 
      update(); 
      render(); 
      if(glfwWindowShouldClose(window)) running = false; 
     } 
    } 

    private void init() 
    { 
     if(!glfwInit()) 
     { 
      System.err.println("GLFW failed to initialize!"); 
      return; 
     } 
     glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); 
     window = glfwCreateWindow(windowWidth, windowHeight, "Game", NULL, NULL); 
     if(window == NULL) 
     { 
      System.err.println("GLFW failed to create the window"); 
      return; 
     } 
     GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 
     glfwSetWindowPos(window, (videoMode.width() - windowWidth)/2, (videoMode.height() - windowHeight)/2); 
     glfwSetKeyCallback(window, new Input()); 
     glfwMakeContextCurrent(window); 
     glEnable(GL_DEPTH_TEST); 
     System.out.println("OpenGL: " + glGetString(GL_VERSION)); 
     glfwShowWindow(window); 
     glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
    } 

    private void update() 
    { 
     glfwPollEvents(); 
     if(Input.keys[GLFW_KEY_SPACE]) 
     { 
      System.out.println("SPACE BAR"); 
     } 
    } 

    private void render() 
    { 
     glfwSwapBuffers(window); 
    } 
} 

Des pointeurs/astuces seraient utiles. Merci d'avance.

+0

Au lieu de liens se serait le mieux pour poster directement votre code ici, surtout si elle est courte (la sortie d'erreur peut être un peu grand mais vous pouvez au moins poster les premières parties qui contiennent normalement les informations les plus importantes de toute façon). En faisant cela, il vous sera plus facile de lire et de comprendre votre question et ainsi les gens seront plus disposés à aider - et enfin, mais pas des moindres: les liens peuvent se rompre avec le temps. – Thomas

+0

@Thomas Merci, je l'ai mis à jour. – smorce

Répondre

1

Il vous manque

GL.createCapabilities();

De l'getting started:

// This line (~the above) is critical for LWJGL's interoperation with GLFW's 
// OpenGL context, or any context that is managed externally. 
// LWJGL detects the context that is current in the current thread, 
// creates the GLCapabilities instance and makes the OpenGL 
// bindings available for use. 

De plus, déplacez glEnable(GL_DEPTH_TEST); après cette ligne aussi bien.

Vous ne recevez pas un accident maintenant sur votre machine, mais vous pouvez avec des conditions différentes

+0

Ah, c'est logique. Merci beaucoup! – smorce