Why did moving some variable declarations after OpenGL context init break the code?How to attach opengl display to a JFrame and dispose of it properly?What are some best practices for OpenGL coding (esp. w.r.t. object orientation)?Why use multiple OpenGL contextPyOpenGL - passing transformation matrix into shaderWorking on a java based chatting application using threadingOpenGL objects cleanup after context destructionLWJGL/OpenGL - Alpha not working using GL_QUAD_STRIP or GL_LINE_STRIPGL_INVALID_ENUM/GL_INVALID_OPERATION after OpenGL 3.1 context creation(OpenGL) Uniform is preserved after context loss?What can cause working OpenGL render code to render black textures if used after some other rendering code?OpenGL : Rendering to multiple contexts code?

Are athletes' college degrees discounted by employers and graduate school admissions?

How to ask if I can mow my neighbor's lawn

Boss making me feel guilty for leaving the company at the end of my internship

New Site Design!

100-doors puzzle

Having some issue with notation in a Hilbert space

Idiom for 'person who gets violent when drunk"

Is it possible for underground bunkers on different continents to be connected?

For Saintsbury, which English novelists constituted the "great quartet of the mid-eighteenth century"?

Background for black and white chart

How to address players struggling with simple controls?

Does anyone recognize these rockets, and their location?

What things do I only get a limited opportunity to take photos of?

Co-worker is now managing my team. Does this mean that I'm being demoted?

Should I move out from my current apartment before the contract ends to save more money?

Difference between "drift" and "wander"

Cant bend fingertip when finger is straight

How did the European Union reach the figure of 3% as a maximum allowed deficit?

How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?

Sci fi/fantasy book, people stranded on a planet where tech doesn't work, magic mist

Do items with curse of vanishing disappear from shulker boxes?

Can I appeal credit ding if ex-wife is responsible for paying mortgage?

Print the phrase "And she said, 'But that's his.'" using only the alphabet

Why doesn't Mathematica completely draw the fit?



Why did moving some variable declarations after OpenGL context init break the code?


How to attach opengl display to a JFrame and dispose of it properly?What are some best practices for OpenGL coding (esp. w.r.t. object orientation)?Why use multiple OpenGL contextPyOpenGL - passing transformation matrix into shaderWorking on a java based chatting application using threadingOpenGL objects cleanup after context destructionLWJGL/OpenGL - Alpha not working using GL_QUAD_STRIP or GL_LINE_STRIPGL_INVALID_ENUM/GL_INVALID_OPERATION after OpenGL 3.1 context creation(OpenGL) Uniform is preserved after context loss?What can cause working OpenGL render code to render black textures if used after some other rendering code?OpenGL : Rendering to multiple contexts code?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















I'm currently working on a Java game and I use OpenGL in an AWT Canvas with LWJGL 2.9.3.
And I actually don't understand why moving some object declarations after Display.create() makes the canvas stop showing anything (glClearColor still works).



Here is the code that works:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



And here is the code that doesn't work:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



These methods are called by the addNotify() method in Canvas initialization.
The complete code is from this answer.
This issue is not really important but I would like to know why just the displacement of a few declarations can entirely break the game.










share|improve this question



















  • 1





    This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

    – httpdigest
    Mar 24 at 21:15






  • 1





    Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

    – httpdigest
    Mar 24 at 21:33











  • Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

    – knacky
    Mar 25 at 19:13

















4















I'm currently working on a Java game and I use OpenGL in an AWT Canvas with LWJGL 2.9.3.
And I actually don't understand why moving some object declarations after Display.create() makes the canvas stop showing anything (glClearColor still works).



Here is the code that works:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



And here is the code that doesn't work:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



These methods are called by the addNotify() method in Canvas initialization.
The complete code is from this answer.
This issue is not really important but I would like to know why just the displacement of a few declarations can entirely break the game.










share|improve this question



















  • 1





    This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

    – httpdigest
    Mar 24 at 21:15






  • 1





    Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

    – httpdigest
    Mar 24 at 21:33











  • Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

    – knacky
    Mar 25 at 19:13













4












4








4








I'm currently working on a Java game and I use OpenGL in an AWT Canvas with LWJGL 2.9.3.
And I actually don't understand why moving some object declarations after Display.create() makes the canvas stop showing anything (glClearColor still works).



Here is the code that works:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



And here is the code that doesn't work:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



These methods are called by the addNotify() method in Canvas initialization.
The complete code is from this answer.
This issue is not really important but I would like to know why just the displacement of a few declarations can entirely break the game.










share|improve this question
















I'm currently working on a Java game and I use OpenGL in an AWT Canvas with LWJGL 2.9.3.
And I actually don't understand why moving some object declarations after Display.create() makes the canvas stop showing anything (glClearColor still works).



Here is the code that works:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



And here is the code that doesn't work:



 private void startGL() 
glThread = new Thread(() ->
isRunning = true;

try
Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
Display.create();
catch (LWJGLException e)
e.printStackTrace();


ArrayList<Entity> entities = new ArrayList<>();
Vector3f lightPosition = new Vector3f(-20.0f, 20.0f, -20.0f);
Matrix4f projMatrix = new Matrix4f();
Camera camera;
EntityRenderer entityRenderer = null;

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

camera = new Camera();
try
entityRenderer = new EntityRenderer();
catch (IOException e)
e.printStackTrace();

projMatrix.setPerspective((float) Math.toRadians(45.0f), dmGetAspectRatio(), 0.1f, 1000f);

while(isRunning)
//rendering and update code


//cleanup code
, "LWJGL Thread");

glThread.start();



These methods are called by the addNotify() method in Canvas initialization.
The complete code is from this answer.
This issue is not really important but I would like to know why just the displacement of a few declarations can entirely break the game.







java opengl lwjgl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 11:48









genpfault

43k956102




43k956102










asked Mar 24 at 20:36









knackyknacky

242




242







  • 1





    This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

    – httpdigest
    Mar 24 at 21:15






  • 1





    Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

    – httpdigest
    Mar 24 at 21:33











  • Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

    – knacky
    Mar 25 at 19:13












  • 1





    This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

    – httpdigest
    Mar 24 at 21:15






  • 1





    Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

    – httpdigest
    Mar 24 at 21:33











  • Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

    – knacky
    Mar 25 at 19:13







1




1





This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

– httpdigest
Mar 24 at 21:15





This looks like a timing issue related to when addNotify() is called on the Canvas and when the glTread creates calls Display.create() which creates the visual and OpenGL context on the Canvas peer. You can just replace your variable declarations with a Thread.sleep(10), and simply render a simple glBegin(GL_LINES) in the loop and the issue is reproducible. I would suggest starting the glThread after you set the window visible.

– httpdigest
Mar 24 at 21:15




1




1





Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

– httpdigest
Mar 24 at 21:33





Btw. for integrating an OpenGL canvas into AWT with LWJGL 2 there is also AWTGLCanvas

– httpdigest
Mar 24 at 21:33













Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

– knacky
Mar 25 at 19:13





Yes, you're right it was a timing issue, I've added 20ms sleep before Display.create and works. thank you. and I will also look for the AWTGLCanvas class.

– knacky
Mar 25 at 19:13












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328320%2fwhy-did-moving-some-variable-declarations-after-opengl-context-init-break-the-co%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328320%2fwhy-did-moving-some-variable-declarations-after-opengl-context-init-break-the-co%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript