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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?