Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a Java game library (too many problems with the existing ones) and I'm building the win64 native right now. In the native I need to handle the window, OpenGL contexts, and advanced algerithms that will be faster in C++. Anyway, the first thing I need to do is the window handling. The thing is that I don't know how to make a loop in Win32 where I create the window, resize it, and update the OpenGL buffers on a single function call.

I've been trying to make a window for the past few hours but I just get errors. I also have no idea to create a OpenGL context.

Can someone show me an example of creating a window, making the OpenGL context, drawing something, and closing it? Also doing things such as resizing it, changing the icon, and simple things like that and make it changed on the next update? I can't seem to find anything that actually works. I know this may sound like a stupid question, or I'm asking for you to make something for me, but I just want an example that works.

share|improve this question
As already informed you in your previous questions, don't try to do this yourself and just use the existing implementations (JOGL or LWJGL). If you have problems with those, ask for help. Many people here have solved the problems themself and can help you too. Only a handful of people have created their own OpenGL Java wrappers and there is a reason for that: It takes a lot of time and is very hard to do well. – msell May 11 at 20:39

closed as not a real question by msell, Anko, Josh Petrie, mh01, bummzack May 13 at 11:53

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

2 Answers

Have you tried like ANY opengl tutorial? Most of them are using WinAPI to create the window and pretty much describe everything you need. Probably the most famous one being that by NeHe: http://nehe.gamedev.net/tutorial/lessons_01__05/22004/ but there are many more on the net.

share|improve this answer
NeHe is not so popular anymore, and apparently says more about us: We both got introduced to OpenGl well over a decade ago ;) – Lo Sauer May 11 at 11:32
@LoSauer Then which tutorial is popular these days? – Thomas May 13 at 9:23
I would say, those coming up top ranked on google. – Lo Sauer May 15 at 5:13

You might want to take a look at the Lightweight Java Game Library, despite your asserted gripe with "the existing ones"

To quote the authors themselves:

LWJGL is primarily an enabling technology which allows developers to get at resources that are simply otherwise unavailable or poorly implemented on the existing Java platform

As for your particular question: an OpenGL window test can be found here. LWJGL is indeed lightweight. For the few library function calls, simply look into the library references through your IDE of choice (Netbeans, Eclipse,...)

You will definitely need set the Viewport and Display. Your mainloop is usually factored into a function which is ultimately called from your public static void main(String[] args) entry point. Taken from the LWJGL example above:

    74          public void execute() {
    75                  initialize();
    76                  mainLoop();
    77                  cleanup();
    78          }


    86           * Initializes the test
    87           */
    88          private void initialize() {
    89                  try {
    90                          //find displaymode
    91                          switchMode();
    92                          // start of in windowed mode
    93                          Display.create();
    94                          glInit();
    95                          quadPosition = new Vector2f(100f, 100f);
    96                          quadVelocity = new Vector2f(1.0f, 1.0f);
    97                  } catch (Exception e) {
    98                          e.printStackTrace();
    99                  }
    100         }

    147         private void render() {
    148                 //clear background
    149                 glClear(GL_COLOR_BUFFER_BIT);
    150                 ...
    166         }


    257         /**
    258          * Initializes OGL
    259          */
    260         private void glInit() {
    261                 // Go into orthographic projection mode.
    262                 glMatrixMode(GL_PROJECTION);
    263                 glLoadIdentity();
    264                 gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
    265                 glMatrixMode(GL_MODELVIEW);
    266                 glLoadIdentity();
    267                 glViewport(0, 0, mode.getWidth(), mode.getHeight());
    268                 //set clear color to black
    269                 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    270                 //sync frame (only works on windows)
    271                 Display.setVSyncEnabled(true);
    272         }

Best of luck!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.