Results 1 to 4 of 4
  1. #1
    type1ninja is offline Member
    Join Date
    May 2014
    Location
    In orbit above Kerbin
    Posts
    4
    Rep Power
    0

    Unhappy Help with LWJGL/OpenGl Rendering

    I suppose I'll cut right to the chase. I'm trying to make a 3D game with LWJGL/OpenGL, and rendering anything simply isn't working.
    I decided to make sure I could render in 2D first, but as it turns out, that isn't working either.
    I've searched on the internet for tutorials on this, but nothing has worked.

    SUPEREDIT: I forgot to mention, my issue is that this code simply opens up a black window. No triangle. What, exactly, am I doing wrong?

    So, here's ALL the code (most of it was taken directly from the "test" program on the LWJGL site; I'll change it to suit my needs after I get rendering working):

    Java Code:
    package com.type1ninja.engine;
    
    import org.lwjgl.Sys;
    import org.lwjgl.glfw.*;
    import org.lwjgl.opengl.*;
     
    import java.nio.ByteBuffer;
     
    import static org.lwjgl.glfw.Callbacks.*;
    import static org.lwjgl.glfw.GLFW.*;
    import static org.lwjgl.opengl.GL11.*;
    import static org.lwjgl.system.MemoryUtil.*;
     
    public class Game {
     
        // We need to strongly reference callback instances.
        private GLFWErrorCallback errorCallback;
        private GLFWKeyCallback   keyCallback;
     
        // The window handle
        private long window;
     
        public void run() {
            System.out.println("Hello LWJGL " + Sys.getVersion() + "!");
     
            try {
                init();
                loop();
     
                // Release window and window callbacks
                glfwDestroyWindow(window);
                keyCallback.release();
            } finally {
                // Terminate GLFW and release the GLFWerrorfun
                glfwTerminate();
                errorCallback.release();
            }
            
            
        }
     
        private void init() {
            // Setup an error callback. The default implementation
            // will print the error message in System.err.
            glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
     
            // Initialize GLFW. Most GLFW functions will not work before doing this.
            if ( glfwInit() != GL11.GL_TRUE )
                throw new IllegalStateException("Unable to initialize GLFW");
     
            // Configure our window
            glfwDefaultWindowHints(); // optional, the current window hints are already the default
            glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
            glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable
     
            int WIDTH = 800;
            int HEIGHT = 600;
     
            // Create the window
            window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
            if ( window == NULL )
                throw new RuntimeException("Failed to create the GLFW window");
     
            // Setup a key callback. It will be called every time a key is pressed, repeated or released.
            glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
                @Override
                public void invoke(long window, int key, int scancode, int action, int mods) {
                    if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
                        glfwSetWindowShouldClose(window, GL_TRUE); // We will detect this in our rendering loop
                }
            });
     
            // Get the resolution of the primary monitor
            ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
            // Center our window
            glfwSetWindowPos(
                window,
                (GLFWvidmode.width(vidmode) - WIDTH) / 2,
                (GLFWvidmode.height(vidmode) - HEIGHT) / 2
            );
     
            // Make the OpenGL context current
            glfwMakeContextCurrent(window);
            // Enable v-sync
            glfwSwapInterval(1);
     
            // Make the window visible
            glfwShowWindow(window);   
        }
     
        private void loop() {
            // This line 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 ContextCapabilities instance and makes the OpenGL
            // bindings available for use.
            GLContext.createFromCurrent();
     
            // Set the clear color
            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity(); // Resets any previous projection matrices
            glOrtho(0, 800, 600, 0, 1, -1);
            glMatrixMode(GL_MODELVIEW);
     
            // Run the rendering loop until the user has attempted to close
            // the window or has pressed the ESCAPE key.
            while ( glfwWindowShouldClose(window) == GL_FALSE ) {
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
     
                glfwSwapBuffers(window); // swap the color buffers
                
                glBegin(GL_TRIANGLES);
                	glVertex2f(200f, 150f);
                	glVertex2f(600f, 150f);
                	glVertex2f(400f, 400);
                glEnd();
                
                // Poll for window events. The key callback above will only be
                // invoked during this call.
                glfwPollEvents();
            }
        }
     
        public static void main(String[] args) {
            new Game().run();
        }
     
    }
    I would also appreciate help on using spoiler/code tags on this forum (if the attempt at tags above didn't work), as well as being pointed to a Java, LWJGL, and OpenGL 3D rendering tutorial.

    Thanks in Advance
    ~Type1Ninja

    EDIT: Hey look, the code tags worked! :D
    EDITEDIT: Do you NEED to have a website to put your package name as something like com.type1ninja.engine, or do you use that form regardless?
    Last edited by type1ninja; 02-06-2015 at 02:23 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Help with LWJGL/OpenGl Rendering

    Sorry, I have no knowledge of LWJGL/OpenGL so I can't help with your main question.

    Quote Originally Posted by type1ninja View Post
    Do you NEED to have a website to put your package name as something like com.type1ninja.engine, or do you use that form regardless?
    The official recommendation can be found in Naming a Package (The Java™ Tutorials > Learning the Java Language > Packages)

    Many recommend using your email address, reversed, if you don't own a domain. For example
    Java Code:
    package com.gmail.username...
    Of course, that does mean that anyone using your API can figure out your email address ;)

    Personally, I use darrylbu as my top-level package. I own that login name on Hotmail, Yahoo!mail, GMail and several other sites, so it's probably fairly unique.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Help with LWJGL/OpenGl Rendering

    As for the main question, I would recommend directing such questions towards java-gaming.org. The developers of LWJGL also visit there. And the LWJGL site also has its own forum.

    Just a general pro-tip: in general forums such as this ask about general questions. If you want help with a very specific third party product and/or discipline (such as game programming), find a forum or mailing list targeting that very specific third party product and/or discipline. You simply maximize the chance of reaching people who have knowledge and understanding what you're after.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    type1ninja is offline Member
    Join Date
    May 2014
    Location
    In orbit above Kerbin
    Posts
    4
    Rep Power
    0

    Default Re: Help with LWJGL/OpenGl Rendering

    Quote Originally Posted by DarrylBurke View Post
    Sorry, I have no knowledge of LWJGL/OpenGL so I can't help with your main question.


    The official recommendation can be found in Naming a Package (The Java„ Tutorials > Learning the Java Language > Packages)

    Many recommend using your email address, reversed, if you don't own a domain. For example
    Java Code:
    package com.gmail.username...
    Of course, that does mean that anyone using your API can figure out your email address ;)

    Personally, I use darrylbu as my top-level package. I own that login name on Hotmail, Yahoo!mail, GMail and several other sites, so it's probably fairly unique.

    db
    Thank you for the info on this; it is good to get this sort of thing cleared up right away.

    Quote Originally Posted by gimbal2 View Post
    As for the main question, I would recommend directing such questions towards java-gaming.org. The developers of LWJGL also visit there. And the LWJGL site also has its own forum.

    Just a general pro-tip: in general forums such as this ask about general questions. If you want help with a very specific third party product and/or discipline (such as game programming), find a forum or mailing list targeting that very specific third party product and/or discipline. You simply maximize the chance of reaching people who have knowledge and understanding what you're after.
    Thank you for the tip. I just didn't want to make *another* forums account.

Similar Threads

  1. LWJGL VBO rendering
    By vastrolorde in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2014, 11:25 PM
  2. OpenGL or LWJGL?
    By Zelaine in forum New To Java
    Replies: 6
    Last Post: 01-22-2014, 07:46 PM
  3. LWJGL Texture Rendering
    By zFollette in forum Advanced Java
    Replies: 5
    Last Post: 01-06-2014, 09:40 PM
  4. One Block. Can use OpenGL.
    By Sly14Cat in forum New To Java
    Replies: 5
    Last Post: 12-30-2012, 12:00 AM
  5. Opengl problem.
    By gyijhbk in forum Android
    Replies: 0
    Last Post: 09-18-2012, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •