I'm trying to get SWT working with the newest JOGL (2.0).
I tried SWT snippet 209, but it doesn't work. The problem is caused by the following line:
final GLContext context = GLDrawableFactory.getFactory().createExternalGLContext();
...but when I change getFactory() to getFactory(GLProfile.getDefault()) (to make it compatible with the new API), it crashes on createExternalGLContext() with javax.media.opengl.GLException: Error: current context null. I don't understand this message: I'm trying to create a new context, and it complains that the current is null. Why?
Maybe there is some other way to create a GLContext?
Or maybe it is possible to use GLEventListener with SWT GLCanvas?
PS. I placed my modified version of the snippet here.
Edit: now I understand the error message. Documentation says:
The underlying OpenGL context must be current on the current thread at the time this method is called.
How to create the first GLContext?
Easy way: Have your rendering class implement GLEventListener and move your GLContext creation code into the .init(...) callback (seems like the right location for the example you posted). Then add that listener to whatever GLCanvas or the like you're using as your display widget.
They cleaned up JOGL a decent bit recently so most examples won't even compile without a decent bit of massaging. If you're new to it, you might want to roll back to an older version with higher code example compatibility while you get spun up.
The tutorial at http://wadeawalker.wordpress.com/2010/10/09/tutorial-a-cross-platform-workbench-program-using-java-opengl-and-eclipse/ shows how to do exactly this. I modified the SWT snippet 209 starting from the JOGL2 version at http://github.com/sgothel/jogl-demos/blob/master/src/demos/swt/Snippet209.java.
My tutorial shows how to do it as an Eclipse RCP app (using only SWT, no AWT bridge). To do it as a standalone SWT app, there's a tutorial at https://sites.google.com/site/justinscsstuff/jogl-tutorials.
Related
Previously in my game engine written in java, I have used lwjgl 2.9.3. I ran into an issue. I wanted lwjgl to run on another graphics card. So I researched and soon figured out, that it would be impossible using lwjgl 2.9.3. So I read about seeing if lwjgl's developers were going to add the option of choosing which graphics card you get to run on. I figured out that lwjgl 3 did have support for this. So I switched over to lwjgl 3. I got everything working and started to work on why I switched. I soon figured out that there is no documentation for changing which graphics card you use. So after hours of testing I figured out that you need to create a WGLARB context. I know you can just use the method: wglCreateContextAttribsARB(long hdc, long sharedContext, Byte/IntBuffer attribList). But it is unclear how to use this method. I am not sure if you use the windows DC Pointer or something else. I know you do not have to put anything in for the 'long sharedContext' so I put 'MemoruUtil.NULL'. So here are my questions:
How do you create a WGLARB context, or more specificly what do you specifically pass in, like do you put in an empty Int/Byte Buffer or do you put data into the buffer before you pass it in as a parameter. I do not know.
From there how do you use: WGLNVGPUAffinity.getInstance().wglCreateAffinityDCNV(gpuList); GPU list is either a PointBuffer or ByteBuffer how do I get this data to pass in in the first place?
Sorry about the long post, but I am very frustrated about the lack of documentation, Thank you in advance!
LWJGL 3 (through GLFW) handles OpenGL context creation. Which means you don't get to handle it. GLFW will create the context, though it does give you some options as to exactly how. But GLFW is cross-platform, so it doesn't give you Windows & NVIDIA-specific options.
However, that doesn't mean you don't get some control. LWJGL 3 also gives you access to the platform-specific APIs (GLX, WGL, etc), as well as extensions to them. So you can use WGL.wglGetCurrentContext to get the context, then use the WGLNVGPUAffinity functions to create affinity contexts. That extension provides all of the various tools for enumerating GPUs and creating new OpenGL contexts that target a specific GPU.
The extension specification is even nice enough to provide sample code for enumerating GPUs. Of course, it's NVIDIA only, but that clearly isn't a problem for you.
I am kind of confused as i am using Eclipse Luna in my kind of big project, and i was using JavaFX fine, for now.
I am trying to implement a Process Dialog as shown in here
And here is a tricky part, my eclipse does not recognize nor know what to do with those few badly importat lines
Dialogs.create()
.owner(stage)
.title("Progress Dialog")
.masthead("Searching for friends")
.showWorkerProgress(service);
The first word in this code gets underlined and a mysterious
Dialogs cannot be resolved
show up as i hover above it..
I can not understand this matter as i use a lot of JavaFX in this project, and i did not have any issues with any part. Alerts, windows and all stuff like that works fine, only this thing is kind of strange for me.
Also, i do use JavaFX ver 8.0.45-b11, and it disturbs me as somewhere i found that
JavaFX has never had a dialogs API, which has always seemed to be a
glaring omission – but no more! It has (finally!!!) been decided that
JavaFX 8u40 will be the first release that will include a dialogs API.
Could someone please tell me if there is any mysterious thing that one must do to use this JavaFX Dialogs API?
No need to use 3rd party dialogs going forward. Learn how to use the dialogs native to jdk8u40+ from this JavaFX Dialogs page.
I've got a Java class that creates a Java3D (1.5.2) Canvas3D, adds some things, rotate it a bit and then saves it as an image - without actually displaying the Canvas3D in a JFrame or similar. That part works fine, based on the Java3D print_canvas3d example.
Unfortunately, the whole thing seems to have troubles cleaning up, because I see two symptoms:
a) After the image is saved, the application should be finished, but it does not exit. Calling System.exit(0) does fix that, but since the class will be used in an application server later, that is not a solution.
b) After the first image is saved, trying to create a second one (by creating a new Canvas3D, etc.) blocks the whole application on GraphicsConfiguration.getDevice() (and, if that is worked around by storing the Device in a static member, on similar places).
So, somehow the cleanup of the Java3D code seems to lack something very important. Unfortunately I can't seem to be able to find that...
I tried the solution given [here], tried to SimpleUniverse.cleanUp, SimpleUniverse.getViewer.getView.attachViewPlatform(null) and other stuff, but nothing seems to change it. The only workaround I found is to place the code inside daemon threads and save the whole Canvas3D part in a static variable, but honestly, that looks more like a mess and not a solution. Unfortunately, I don't have the time left to rewrite the whole thing in JOGL or similar and I also can't simply create an external application to write the image and exit for each call... So I need to know how to do it correctly.
My question is simple: How do I clean up a Java3D application correctly without System.exiting it?
Regards,
Flo
How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.
I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism
I wonder if someone can help me... I've been developing VB.Net for years and C++/VB before that. I've also got some PHP experience. I'm now moving to Java to write an app for my Android mobile. I'm trying to use MOTODev Studio (Which extends eclipse)
I've not developed in Java before so it's a bit of a learning curve anyway. I'm fairly confident I'll be able to work out the important bits but I'm in a new IDE in a new language developing for a new platform.
As I'm new to Java, I was hoping to be able to rely on auto-code generation, intellisense, etc. I'm starting to think this was either very optimistic or I'm using eclipse very poorly.
For example, I know I need to override the OnClickListener() event but am unsure of the exact syntax. In VS, I'd just start typing Override in a class and up would pop intellisense with everything I can override and the appropriate signature, however, in eclipse none of the intellisense options seem to apply when I type public voidor #Override. Is this because I'm doing something wrong/is eclipse intellisense incomplete not very good?
In VS there's a bar at the top of the code page which lists objects in the file on the left and methods of the current object on the right. Does eclipse have an equivalent? If so, where?
I've managed to use the IDE to the extent that I've got a "Hello World" installed on my mob so it's more code generation techniques than windows/dialogues/etc.
I suppose what I really need is for someone to recommend some good resources to help me transition. I'd also appreciate any comments or advice from others that have done similar
Thanks in advance
So you learning three items at once
Language (Java)
Platform (Android)
Tool (Eclipse)
Here are my two cents for each of them:
Java - besides annotations guide already mentioned by Falmarri all java tutorials on oracle site are worth seeing you can find them here
Android - From my point of view very good entering points into android development are Android Developer Dev guide and API Demos project which demonstrates many android aspects ( You can add this project into your workspace in Eclipse via ->New Android Project-> Select from sample ->Choose target version -> Click OK , Voila you have new project in your workspace with a lot of useful android related code, describing many advanced and not so advanced topics). BTW Android developers blog is worth reading but
it usually covers more advanced topics
Eclipse - Falmarri already pointed and pretty good tutorial about Eclipse, I from my side would suggest to start from Help-> Help Contents -> Java Development User Guide
It covers all basic tasks and concepts. For your particular problem with overriding ( actually implementing) an interface method you've to first indicate that your class implements View.OnClickListener via class MyClass implements OnClickListener at this point eclipse will notice that you claiming to implement interface but didn't actually implemented some of it methods ( in this situation onClick(View v)) and will mark class declaration with error marker. Go to your class declaration and press Ctrl + 1 ( also known as "quick fix") and you will get some options to fix broken code. At the other hand if you really want to override parent class method you can press Ctrl + Space in a class body ( e.g not inside the method) and you will get option to override avalible methods.
Hope it helps
http://download.oracle.com/javase/tutorial/java/javaOO/annotations.html
yes, it's the default java perspective. Have you even installed the IDE yet?
http://www.vogella.de/articles/Eclipse/article.html
I'm not entirely sure I fully understand your questions, but if I'm in a Java class in Eclipse that implements some Interface and I want to implement methods I either select the quick fix (Ctrl+1) for the compiler error telling me I'm not implementing the Interface or I trigger content assist (Ctrl+Space) in the class body to get a list of methods to override. And with the bar you mention, do you mean something like the breadcrumb navigation (Alt+Shift+B)?