java,opengl,collision-detection,lwjgl,collision
There is a problem with your model. Using three arrays may save memory, but it also changes the model, creating "shadows" that your archers can collide with. Let's say that you have vertices in (1,1,1) and (2,2,2). Using your model, there will also a vertex at (1,2,2) and any other...
Since @DietrichEpp already covered some higher level approaches, I'll focus on some direct suggestions on your current code. In case you're not ready to make the jump, I think you could get substantial improvements from just fixing the first item. There is a glGetFloat(GL11.GL_MODELVIEW_MATRIX, ...) call in your rendering code....
You should not need to do any keyboard scanning if you use the glfwGetKey or glfwSetKeyCallback functions to receive input. Their documentation states The key functions deal with physical keys, with layout independent key tokens named after their values in the standard US keyboard layout If you need the actual...
LWJGL 3 has the focus on the OpenGL bindings. On the wiki it is stated The library includes functionality and APIs that simply should never have been added to it. Such functionality belongs either to an engine using LWJGL, or to another library layered on top of LWJGL. This includes...
You need to bind the texture before you load the image data in to it. If you don't glTexImage2D doesn't know where to load the data. You can bind the texture by calling: GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); Before: GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); You should also call these...
The reason why your camera doesn't move is that you create a new instance of player and controls in every frame. In addition to this, you change the members only in controls, but use the values in player to set the view.
On line 91 DisplayMode.getWidth() and DisplayMode.getHeight() are static method calls, but it seems these are not static methods. Looking at the code snippets here, it seems like you're supposed to construct a DisplayMode object and call Display.setDisplayMode() to register the object you constructed. As an aside, I don't see DisplayMode...
java,opengl,glsl,lwjgl,directional-light
I figured out the problem, when I rendered the text to the screen (the text that describes the problem with the cube), I forgot to set the glBlendFunc() back to this setting, glBlendFunc(GL_ONE, GL_ZERO); This was causing the transparency issue and also fixed some other problems....
First sampler2D is a type not a uniform, so I interpret the questions a the following: I did not set myTexture to any value, why does it still work? To access a texture in a shader with a sampler object the number of the texture unit has to be passed...
Inserting TextureImpl.bindNone() before every call to render text seamed to fix the problem. I am still onshore where the problem came from because ive used the slick util text render before without using TextureImpl.bindNone() without problems.
The code actually works exactly as it should. The real problem is that the error I was expecting, java.lang.UnsatisifiedLinkError, is not an Exception but actually an Error. Amending the code to catch a Throwable solves this issue.
I learned a lot from Oscar from TheCodingUniverce, here's his playlist. It is in LWJGL 2. I really doubt you'll find any LWJGL 3 tutorials because its still not had a 1.0 release yet, If you're new to LWJGL or Java I strongly recommend not using an untested library.
There is, as of this moment time, no Java support on the Unreal Engine. There is a C# plugin available however, you could probably explore how they accomplished it if you plan on making your own wrapper.
A CLASSPATH entry is either a directory at the head of a package hierarchy of .class files, or a .jar file. If you're expecting ./lib to include all the .jar files in that directory, it won't. You have to name them explicitly.
java,floating-point,textures,lwjgl,pixels
Sorry for the quick asking, I found the answer by looking in the javadocs for Slick-util. To get the size of the original image, use Texture.getImageWidth() and Texture.getImageHeight()....
I'm not familiar with GLFW in particular but found GLFW_REPEAT which might be what you're looking for (the documentation of it was lacking to say the least). If that doesn't work it's not uncommon to use shadow registers for keyboard input, where you update the state of every key of...
Create a Map<Character, Consumer<Character>>. Create a class for each character which implements Consumer<Character> interface. Store objects of those classes in the map. Call consume on the appropriate consumer object from the map using your detected keystroke character. Hope this helps....
There are two things you can do If you draw your skybox first, you can disable your depth test glDisable(GL_DEPTH_TEST) or your depth write glDepthMask(false). This will prevent that your skybox draws depth values, and the skybox will never be in front of anything that will be drawn later. If...
I've modified tick method: @Override public void tick(float aTick) { float m01 = matrix.get(1); float m02 = matrix.get(2); float m04 = matrix.get(4); float m06 = matrix.get(6); float m08 = matrix.get(8); float m09 = matrix.get(9); float m12 = matrix.get(12); float m13 = matrix.get(13); float m14 = matrix.get(14); buffer.put(matrix); buffer.put(1, m04); buffer.put(2,...
According to the documentation Attribute bindings do not go into effect until glLinkProgram is called You seem to link only once and that appears to be before you call genAttribList which is the function that calls glBindAttribLocation. So, use glLinkProgram again at the end of genAttribList would be my suggestion....
first call callGl() then draw your frame... because if you draw anything before using glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); then you will get a black screen :) try to put m.Update(); inside render method.... because you need to render your text in every frame... not just once ;) public void Render() {...
I never got an answer to this, but I figured it out with some help from some friends. To handle this problem, I created a class that does a lot of the math automatically. public class Rot2D { public static Rot2D fromDegrees(double angle) { return fromRadians(Math.toRadians(angle)); } public static Rot2D...
Math.atan2 returns its value in radians, not degrees. To convert to degrees, multiply by either 180/pi or 360/(2 pi): float ans = angle * 180 / Math.PI; Java even has a builtin function for this, Math.toDegrees: (thanks @yshavit) float ans = Math.toDegrees(angle); Also, what @yshavit says in the comments: you...
Well, the lookAt code provided by that library is just this (I'm leaving the actual source code out and only keep the comments, as they nicely explain the steps which are done): public final static void lookAt(Vector3f position, Vector3f centre, Vector3f up, Matrix4f dest) { // Compute direction from position...
java,linux,intellij-idea,lwjgl,nativelibrary
So, well, the error wasn't on my side. LWJGL 3 is under heavy development currently and the latest stable version wouldn't match the example, thus I had to use the latest nightly. (The api changed significantly) My solution is: Add the jars as libs and add the .so files as...
Display.getWidth() and Display.getHeight() should do what you want.
Unfortunately, there currently isn't any support for using LWJGL3 with Swing. Support for more windowing systems is in the roadmap, but it isn't clear whether it will be implemented at all. From the roadmap: Multiple windowing system implementations. [✓] GLFW LWJGL 2 compatible [?] AWT/Canvas [?][.x] JavaFX One lesson learned...
From the GLFW Window Guide: Window creation hints There are a number of hints that can be set before the creation of a window and context. Some affect the window itself, others affect the framebuffer or context. These hints are set to their default values each time the library is...
LWJGL uses its own variables for the path to the native libraries (If they are not found you will get a "no LWJGL in path"-error): System.setProperty("org.lwjgl.librarypath", new File("pathToNatives").getAbsolutePath()); If you kept the file structure from the LWJGL package you can use something like this: switch(LWJGLUtil.getPlatform()) { case LWJGLUtil.PLATFORM_WINDOWS: { JGLLib...
The compiler can not only eliminate completely unused variables, but also values that do not contribute to the result. In your code, top is used here: if (top == 1) { myTc.y = top - myTc.y; } But myTc is not used later in the shader. So the value of...
Your call to buffer.flip() is in the wrong place. From the documentation: Flips this buffer. The limit is set to the current position and then the position is set to zero. Where limit is defined as: A buffer's limit is the index of the first element that should not be...
OK Looks like there is a bit of an issue with the way that the -Djava.library.path works. If you pull from Maven you get a lwjgl-platform-2.8.2-natives-windows.jar this file contains the DLLs so you have to Extract the dlls into a folder and point the librarypath to that....
java,lwjgl,models,collision,detection
You have a few options here. The easiest is to simply create an axis-aligned bounding box (AABB) around the object; this can be done algorithmically by simply finding the minimum and maximum values for each axis. For some applications this will work fine, but this obviously isn't very precise. It's...
Vertex Buffers are not something you enable or disable - LWJGL is misleading you. You need to undertand that the glVertexPointer command uses whatever is bound to GL_ARRAY_BUFFER ("Array Buffer Object") as its memory source (beginning with OpenGL 1.5). In certain versions of OpenGL (1.5-3.0 and 3.1+ compatibility) if you...
On my ASUS desktop, I have Realtek HD Audio Manager setting the Default Audio format to 24Bits 44800 Hz, thus my open AL applications are not able to request a 44100 Hz device. Changing that default format to 44100 will help solve the problem. I wish it could help, because...
The order of calls you have in the shader setup code will not work as intended: GL20.glLinkProgram(pId); GL20.glBindAttribLocation(pId, 0, "in_Position"); GL20.glBindAttribLocation(pId, 1, "in_Color"); glBindAttribLocation() needs to be called before glLinkProgram() to take effect. From the man page: Attribute bindings do not go into effect until glLinkProgram is called. After a...
The problem is that ByteBuffer.allocateDirect allocates the buffer in big endian format, no matter on what machine the code runs. ("All x86 and x86-64 machines [..] are little-endian") The solution is either swap the bits manually or just use the BufferUtils class of LWJGL which creates the ByteBuffer in the...
The problem is with the way you're calling getFloat(). When you call it with an index on a ByteBuffer, the index is the number of bytes into the buffer at which to start reading the float, not the number of floats. You need to multiply each of your indices by...
Simple. float[16] transMatrix; glGetFloatv(GL_MODELVIEW_MATRIX, transMatrix); ...
I think your problem is with matrices. When you call glTranslatef, you are transforming the OpenGL ModelView matrix. However, since OpenGL is a state-based machine, this transformation is preserved for further drawing events. The second rectangle will be translated twice. What you want to do is use the OpenGL matrix...
Use GL11.glPushMatrix to save the old matrix and GL11.glPopMatrix to restore it. In renderTexturedCube (or wherever you want): GL11.glPushMatrix(); // saves the current matrix GL11.glTranslatef(x, y, z); GL11.glRotatef(0, 0.0f, 0.0f, 0.0f); // not sure why you have this; it does nothing // rest of cube rendering code goes here GL11.glPopMatrix();...
VorbisJava does exactly this. There is a reasonable example in the tools directory. https://github.com/Gagravarr/VorbisJava/blob/master/tools/src/main/java/org/gagravarr/vorbis/tools/VorbisCommentTool.java VorbisFile vf = new VorbisFile(new File(inFile)); Also, Java Sound API has an extensible service provider model. You can add OggVorbis as a provider. See How can I decode OGG vorbis data from a ByteBuffer?...
You need to call glfwMakeContextCurrent to bind the OpenGL context to your thread. There's a working example on the LWJGL website as well.
Try this one: public void rotate(float angle){ this.rotation = angle; double cos = Math.cos(rotation); double sin = Math.sin(rotation); double xOffset = (x[0]+x[2])/2; double yOffset = (y[0]+y[2])/2; for(int i = 0; i < 3; i++){ x[i] = (float)(cos * (x[i]-xOffset) - sin * (y[i]-yOffset)) + xOffset; y[i] = (float)(sin * (x[i]-xOffset)...
For those who find this in the future, I did find a fix: You cannot, should there be no physical buttons, use the Mouse.isButtonDown() method. Instead, you are going to have to read the event buffer. To do so, I wrote my own helper class: public class Mouse{ private static...
basically what you need is to add slick.jar and lwjgl.jar to your build path and then right click your project >> open properties >> click on Java Build Path >> open Libraries tab >> expand JRE System Library >> click Native library location >> edit >> External Folder >> find...
You have transposed your calls to glUniform1i (...) and glUseProgram (...). At the time that glUniform1i(glGetUniformLocation(shaderProgram, "tex"), 0); is executed, the currently active program is 0 and that should in fact be generating the following error: GL_INVALID_OPERATION is generated if there is no current program object. If you swap the...
Here is a code snippet of with the basis for my FPS style camera. As you can see I am calculating the delta of the mouse position with the center of the screen along the X and Y axis. You can see in my System.out.println calls the values I am...
You need to install the xorg-xrandr package, see http://badlogicgames.com/forum/viewtopic.php?f=11&t=18801...
You need to call glViewport() with the FBO dimensions after binding it, and before starting to render. Note that the viewport dimensions are global state, not per-framebuffer state, so you also have to set them back when you render to the default framebuffer again. With the numbers you use in...
java,opengl,glsl,lwjgl,framebuffer
The problem ended up being that my vertex shader's out variable name didn't match the fragment shader's in variable name (doh). The code posted above is 100% correct in case anyone sees this in the future.
From the OpenGL 3.3 Reference Pages: GL_INVALID_OPERATION is generated if there is no current program object. You bind your shader program in the render() method of Game: public void render() { shader.bind(); mesh.draw(); } However, as seen in the MainComponent class from Tutorial 11: private void run() { // ......
java,lwjgl,computational-geometry,slick2d
The answer here is going to wind up being mostly a question of math. I briefly go over the math/physics involved and trust that you should be able to implement the math/physics in code yourself. How projectiles are supposed to bounce off of walls In classical physics, or at least...
Although the actual issue may be resolved: This is probably related to some "magic" that is done in LWJGL, and may be related to LWJGL Display mounted on Canvas fails to generate Mouse Events - so if you used a Frame instead of a JFrame, it should already work. However,...
For some reason while in a different position at the start you have to multiply the sx and sy equation by a -1. public Bullet(double mx, double my, double px, double py){ if(x==640 && y== 320){ sx = mx-px; sy = py-my; x = px; y = py; sx =...
Since nobody has answered this, and I have found a solution, inefficient as it may be, here's an answer. I Changed the line glOrtho(0,Display.getWidth(),Display.getHeight(), 0 ,1, -1); to glOrtho(0,Display.getWidth(), 0,Display.getHeight(),1, -1); Which means instead of the top being the top, the top is now the bottom of the screen. I...
What you want is an axis aligned billboard. First take the center axis in local coordinates, let's call it a. Second you need the axis from the point of view to some point along that axis (the tree's base will do just fine), let's call it v. Given these two...
Finally figured it out. The part that is missing is the fact that pixels with a depth greater than .9999 (or some other max depth number) need to be discarded so that you aren't trying to blur over pixels that aren't part of the simulation. Obvious in retrospect, took me...
That game appeaers to be using an orthographic projection - notice how the thing farther away from the camera are not smaller. That is why the direction of lines doesn't depend on the camera position. The left half of this picture shows a grid of crates rendered with a perspective...
opengl,rendering,shader,lwjgl,renderer
The main problem is in your vertex shader: gl_Position = mvp * vec4(vertex, 0.0); When expanding regular 3D coordinates to homogeneous coordinates, you need to set the w component to 1.0. So the statement should look like this: gl_Position = mvp * vec4(vertex, 1.0); It's also slightly odd that you...
The old utility classes like Display, Keyboard, Mouse etc. have been removed in LWJGL3. The libary now uses GLFW for window management, which is more complicated but said to have better performance and more features. Like with OpenGL methods, all glfw methods are static and found in the org.lwjgl.glfw.GLFW class....
Got it to work with: java -Djava.library.path=lib\native\windows\x64\ -cp bin;lib\*; Space Apparently there shouldn't be quotations around the path, and it should point to a directory not a file....
You should leave out the Math.floor() condition.What you could get right now is that the player for example is at x=1 and the monster at x=1.99. The Floor condition would shorten this to 1 == 1 and declare that both are at the same place. In the worst case this...
java,while-loop,condition,lwjgl
In your second version, Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) is evaluated once and its value is assigned to ESC, which remains constant. It's either always true or always false (more likely). Your first version evaluates !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) on each iteration of the loop, so it can detect when ESC is actually pressed. If you change...
return (System.nanoTime() * 1000) / 1000000; Isn't this too high compared to your divisor 50. This is like a lot of pixels per second, i.e. 2e4. Please, don't overuse constants, if not at all, use named variables instead. public static final int PIXELS_PER_SECOND = 100 This rule always applies in...
opengl,matrix,glsl,shader,lwjgl
The matrix itself looks ok. Remember that OpenGL uses column-major storage for matrices by default, so the elements for this matrix would be ordered like this when you specify it: {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, x, y, z, 1.0f} If you want to...
java,opengl,rendering,lwjgl,framebuffer
I'm not tooooo familar with OpenGL but Instead of glEnable(GL_TEXTURE_2D); initFramebuffer(); you should set texturing enabled after initializing fb: initFramebuffer(); glEnable(GL_TEXTURE_2D); this is caused by glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); which seems to render uninitialized (non-fb texture) in front of your fb texture box, which causes blank screen...
In OpenGL texture coordinates are given from [0,0] (meaning bottom left corner) to [1,1] (upper right corner). When texture coordinates are out of this range and GL_TEXTURE_WRAP_[R|S|T] is set to GL_REPEAT (as by default), the actual lookup positions into the texture are calculated by lookup.xy = fract(texCoord.xy) In the special...
glsl,lwjgl,slick2d,vertex-shader,blending
a) vertColor = vec4(0.5, 1.0, 1.0, 0.2); b) gl_FragColor = vertColor; the shader does exactly what you asked of it - it sets the color of all fragments to that color. If you want to blend colors, you should add/multiply them in the shader in some fashion (e.g. have a...
OK, I managed to solve this. I was dividing as a float, so I ended up with decimal places which messed up the coordinates. Revised code: import java.awt.image.*; import java.io.*; import java.nio.*; import javax.imageio.*; import org.lwjgl.*; import org.lwjgl.opengl.*; public class OpenGLFontRendererTest { private static int textureID; public static void main(String[]...
The solution is to specify an absolute path for java.library.path, rather than a relative one. On the LWJGL forums, there was a user with a similar problem (I found this by searching for the problematic line and doing some hunting on the forum). The relevant part of the conversation is:...
LWJGL3 has a built in binding to STB which can load TTF font files, there are examples in the LWJGL3 repo which show you how to render text using it. Further details and examples for the same can be found here....
The data arrangement you are using for your attributes is typically called "interleaved", and is in fact the recommended way of storing multiple attributes in a VBO. It favors local data access because all attributes for a vertex are next to each other in memory, which in turn tends to...
java,opengl,lwjgl,nvidia,gldrawarrays
I found it: glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); ... glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); All client states have to be deactivated after every call on NVIDIA components....
java,opengl,lwjgl,bufferedimage
OpenGL 1.2+ supports a GL_BGRA pixel format and reversed packed pixels. On the surface BGRA does not sound like what you want, but let me explain. Calls like glTexImage2D (...) do what is known as pixel transfer, which involves packing and unpacking image data. During the process of pixel transfer,...
Well, as Vincent said, it seems that there's no way to do that as simple as with glut. But we can do that with more code. Spektre contributed a way in his comment. This is a way I found to do that using the sphere's parametric equation: import org.lwjgl.glfw.*; import...
java,opengl,3d,rendering,lwjgl
I'm using GL11.GL_TRIANGLES cuz that's how I can make models' lines show up instead of faces. Well, GL_TRIANGLES is for rendering triangles, which are faces. If you only want the models' lines, you can use one of the line drawing modes (GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP etc). However, a better way...
Your code does not correctly generate the vertex data suitable for the GL. As you know, in the obj format, there is an separate array for vertex position, normals, texcoords and so on. And faces are formed by independetly indexing into them. In the GL, a vertex is the set...
OK, I know where the issue lies, and I'm pretty certain it's a bug in libgdx. I also have a workaround, although it's a little hacky. The Problem When GlyphLayout wraps a line on a space character, it optimises out the terminating space. So with the space removed, the total...
OpenGL state variables don't nest. This is essentially the same as doing bool scissor_test_enabled; scissor_test_enabled = true; ... scissor_test_enabled = true; ... scissor_test_enabled = true; Scissor testing won't help you with your problem. You should look at stencil testing: Using the stencil buffer you can draw arbitrary shapes, having color...
Is there any special thoughts about the 2 first translates in the rotation code? The x ans z translations will cancel each other out but not the y axis. Which could be the source of the problem. vTrans.set(transx + x, (float) (transy + y), transz + z); Matrix4f.translate(vTrans, model1, model);...
The mip-mapping modifies the texture, but the grass doesn't really do much work in the texture anyway as it is a small object. Most of the work to render the grass comes in processing all of the vertices, and most especially if the grass are lots of small objects then...
In this code sequence in the ShaderProgram constructor: if (glGetProgrami(id, GL_LINK_STATUS) == GL_FALSE) { System.err.println(getLogInfo(id)); id is a program id. You pass it to the getLogInfo() method: public static String getLogInfo(int obj) { return glGetShaderInfoLog(obj, glGetShaderi(obj, GL_INFO_LOG_LENGTH)); } Both glGetShaderInfoLog() and glGetShaderi() expect a shader id as the first argument....
The solution was pretty simple, thanks P.T. for the help. I don't know what was wrong, but no OpenGL apps could be run at all actually, and a simple reboot solved the issue for me....
Well, a byte is a byte. It can only have 256 different values. There is a slight oddity related to the index range when using Java OpenGL bindings. Since Java does not have unsigned data types, the maximum supported value may seem to be 127. But since the arrays of...
To create a matrix representing the inverse transform to the one above, apply the transforms in reverse, with negative quantities for the rotation and translation and an inverse quantity for the zoom: glRotatef(-ROTATION, 0, 0, 1); glTranslatef(-this.position.x, -this.position.y, 0); glScalef(1.0f / this.zoom, 1.0f / this.zoom, 1); Then multiply by the...
My first recommendation would be to start getting used with "handling my inputs in the middle of code for another purpose". Now, if you really don't want to do that, then you can try this: public class Main { public static void main(String[] args) { glfwSetKeyCallback(window, new GLFWKeyCallbackProxy()); } class...
In a forum post it is stated: LWJGL3 doesn't include the WaveData from LWJGL2 but it still works the same in LWJGL3, just grab it from the LWJGL2 source code and include it in your project. So it should be safe to just copy the old WaveData class and use...
java,opengl,textures,lwjgl,texture2d
Ok. That came up to work with immediate mode rendering and buffer objects. That also happened like magic. Immediate mode rendering was fixed by enabling GL_TEXTURE_2D (blame myself) and disabling GL_VERTEX_ARRAY and GL_INDEX_ARRAY. VBO was fixed after i just tried this time. I think that was my state changed bug,...