Hello Guest

Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Bug Reports / RFE / Re: Nuklear segfault reading
« Last post by spasi on December 24, 2019, 13:58:41 »
The buffer containing font data must not be GCed or deallocated. It is being accessed directly by stb (e.g. for metrics, the stbtt_GetCodepointHMetrics call in your case), even after you initialize the font textures etc.
22
Bug Reports / RFE / [SOLVED] Nuklear segfault reading
« Last post by mudlee on December 24, 2019, 13:24:54 »
Merry Christmas!

I need help to parse SIGSEGV logs.
I decided to move from NanoVG to Nuklear and I did nothing really, just included the democode (https://gist.github.com/mudlee/c32e5e939fac792dc1e7721376116a0f) to prove it works and of course I'll be refactor it to be a UI framework. After a while it segfaults.

OK, in paralell adding Nuklear, I did a bigger refactor in the engine, and I experience the following. Just calling
Code: [Select]
new NuklearHandler() right after I initiate my engine works and everything starts up, there is the demo Nuklear UI with fonts and texts and buttons.
After a while (1s-~5sec) the game shuts down with segfault. If I don't initiate NuklearHandler, my game does not even start, just hangs around. Obviously I screwed up something during the refactor, but I'd like to find what, but I have no info how to read these segfaults (https://gist.github.com/mudlee/534d973a7cc652f489217a6f04aa8bc2). Somewhere in the past one of you explained how to read it, but I can't find it.
23
OpenGL / lwjgl box color leaking to background
« Last post by Animus_Surge on December 21, 2019, 22:07:54 »
I have a color that keeps leaking to the background whenever I try to draw a rectangle to the screen with that color. Here is what it looks like before: see first image (sorry don't know how to use the img tags) and here is what it looks like after swapping the screen: see second image

Here is the code for the class that draws the rectangle:

Code: [Select]
package com.programwings.wofrpg.display.drawable.components;

import com.programwings.wofrpg.display.screens.MainMenu;
import com.programwings.wofrpg.util.Color;
import com.programwings.wofrpg.util.Coordinate;
import com.programwings.wofrpg.util.Dimension;
import com.programwings.wofrpg.util.logcat.LogCat;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.BufferUtils;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.stb.STBImage.stbi_image_free;
import static org.lwjgl.stb.STBImage.stbi_load;

public class TextBoxComponent {

private int picturei;
public int inputType;
private double width, height;
private Color boxColor;
private String hint, picture;
private Coordinate topLeft;

public TextBoxComponent(Coordinate topLeft,
double width,
double height,
String hint,
String picture,
int inputType,
Color boxColor) {
this.boxColor = boxColor;
this.height = height;
this.hint = hint;
this.picture = picture;
this.inputType = inputType;
this.topLeft = topLeft;
this.width = width;
if(picture != null) {
IntBuffer wi = BufferUtils.createIntBuffer(1);
IntBuffer hi = BufferUtils.createIntBuffer(1);
IntBuffer con= BufferUtils.createIntBuffer(1);

ByteBuffer data = stbi_load(picture, wi, hi, con, 3);
this.picturei = glGenTextures();

glBindTexture(GL_TEXTURE_2D, this.picturei);
int wid = wi.get();
int hei = hi.get();

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,  wid, hei, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
try {
stbi_image_free(data);
} catch(NullPointerException e) {
new LogCat("components").log("An error has occoured while freeing images. [[java.lang.NullPointerException::ln57]]", LogCat.STDERR);
e.printStackTrace();
}
}
}

public Dimension getDimensions() {
return new Dimension(width, height);
}

public Coordinate getTopLeftCornerPoint() {
return topLeft;
}

public String getHint() {
return hint;
}

public void setBoxColor(Color c) {
boxColor = c;
}

Coordinate[] vertices;

public void draw(@Nullable String text) {
try {
if (picture == null) {
vertices = new Coordinate[]{topLeft, new Coordinate(topLeft.x + width, topLeft.y), new Coordinate(topLeft.x + width, topLeft.y - height), new Coordinate(topLeft.x, topLeft.y - height)};
glBegin(GL_QUADS);
glColor4d(boxColor.r, boxColor.g, boxColor.b, boxColor.a);
glVertex2d(topLeft.x, topLeft.y);
glColor4d(boxColor.r, boxColor.g, boxColor.b, boxColor.a);
glVertex2d(topLeft.x + width, topLeft.y);
glColor4d(boxColor.r, boxColor.g, boxColor.b, boxColor.a);
glVertex2d(topLeft.x + width, topLeft.y - height);
glColor4d(boxColor.r, boxColor.g, boxColor.b, boxColor.a);
glVertex2d(topLeft.x, topLeft.y - height);
glEnd();
} else if (boxColor == null) {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, picturei);
glBegin(GL_QUADS);
glTexCoord2d(1, 0);
glVertex2d(topLeft.x, topLeft.y);
glTexCoord2d(0, 0);
glVertex2d(topLeft.x + width, topLeft.y);
glTexCoord2d(0, 1);
glVertex2d(topLeft.x + width, topLeft.y - height);
glTexCoord2d(1, 1);
glVertex2d(topLeft.x, topLeft.y - height);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
} else {
throw new IllegalStateException("An error has occoured within the system.");
}
} catch(NullPointerException e) {
new LogCat("components").log("Something happened while trying to draw a com.programwings.wofrpg.display.drawable.components.TextBoxComponent to a screen. Unable to continue. [[java.lang.NullPointerException::unknown line number]]\n" +
"", LogCat.STDERR);
MainMenu.displayMainMenu();
}
}

public boolean isClicked(double px, double py) {
//System.out.println((px >= topLeft.x && px <= vertices[1].x) && (py >= vertices[2].y && py <= topLeft.y));
return (px >= topLeft.x && px <= vertices[1].x) && (py >= vertices[2].y && py <= topLeft.y);
}

}

where a Coordinate is a point on the screen in OpenGL units (two doubles, one for x and one for y), and a Color is a 4 double constructor that forms the box color.

If it helps, here is the class for the screen that is being drawn:

Code: [Select]
package com.programwings.wofrpg.display.screens;

import com.programwings.wofrpg.display.Primary;
import com.programwings.wofrpg.game.handlers.MouseHandler;
import com.programwings.wofrpg.util.Color;
import com.programwings.wofrpg.util.Coordinate;

import java.util.concurrent.atomic.AtomicBoolean;

import static com.programwings.wofrpg.display.vars.Images.*;
import static org.lwjgl.glfw.GLFW.*;

public class NewCharMenu {

public static void drawNewCharMenu() {

AtomicBoolean isShowing = new AtomicBoolean(true);

glfwSetKeyCallback(Primary.w, ((window, key, scancode, action, mods) -> {
if(key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
isShowing.set(false);
}
}));

while(isShowing.get()) {
glfwPollEvents();

if(glfwWindowShouldClose(Primary.w)) break;

//mouseInput
if(glfwGetMouseButton(Primary.w, GLFW_MOUSE_BUTTON_LEFT) == 1) {
Coordinate mouseCoord = MouseHandler.getMouseCoords(Primary.w);
//if(testTextBox.isClicked(mouseCoord.x, mouseCoord.y)) {
// testTextBox.setBoxColor(new Color(1, 0, 0, 1));
//} else {
// testTextBox.setBoxColor(new Color(0, 1, 1, 1));
//}
}

mmbkg.draw();

testTextBox.draw("test i guess");

glfwSwapBuffers(Primary.w);
}
MainMenu.displayMainMenu();
}

}

Can someone help me?
Thanks

-Surge

EDIT 1: I also ran it with lwjglx debugger and got this following warning stacktrace:
Code: [Select]
[warn ][1] OpenGL debug message
  ID: 0xD
  Source: API
  Type: DEPRECATED BEHAVIOR
  Severity: MEDIUM
  Message: API_ID_DEPRECATED_TARGET deprecated behavior warning has been generated. Enable of GL_LIGHTING capability is deprecated.
  Stacktrace: org.lwjgl.system.JNI.invokePV(Native Method)
              org.lwjgl.glfw.GLFW.glfwSwapBuffers(GLFW.java:4565)
              org.lwjglx.debug.glfw.GLFW.glfwSwapBuffers(GLFW.java:507)
              com.programwings.wofrpg.display.screens.NewCharMenu.drawNewCharMenu(NewCharMenu.java:43)
              com.programwings.wofrpg.display.screens.MainMenu.displayMainMenu(MainMenu.java:25)
              com.programwings.wofrpg.display.Primary.loop(Primary.java:143)
              com.programwings.wofrpg.display.Primary.run(Primary.java:39)
              com.programwings.wofrpg.Runnable.run(Runnable.java:21)
              com.programwings.wofrpg.Runnable.main(Runnable.java:26)

It points to the
Code: [Select]
glfwSwapBuffers() method in the second class that I gave.
24
OpenGL / Re: JAWT - getting drawing surface from jPanel
« Last post by Aisaaax on December 18, 2019, 04:20:54 »
In the end, I had zero problem with Z-layering. What I had problems with is elements - even invisible ones - cutting out shapes in Canvas.

The thing is, the way Swing and AWT interaction is done is thus:
Heavyweight elements DO display on top of lightweights ALWAYS. It may not seem like that, but they really do, because all of the displaying of lightweights is done essentially by the closest heavyweight Ancestor. Thus, if Canvas belongs to a JPanel, and lightweights also belong to JPanel - then you essentially have two "Windows" drawn - JPanel and it's child window Canvas on top of it.

The way java implemented a workaround is a bit convoluted. Basically, any element that is Z-ordered above canvas - cuts a hole in your canvas and peeks through it. The illusion is that your lightweight is on top of Canvas - but it really is below. It simply cut a hole.
The problem with that is that you get problems like this:
https://stackoverflow.com/questions/59321794/swing-layering-transparent-component-ignores-underlying-awt-element

I've spent quite a bit of time trying to figure out exactly what's going on and how to work around that. And as you can see in the above link - there's a solution to make your elements at least of a desired shape, or hide them completely if they're just a container that's supposed to be transparent anyway.
The downside that you can't really make complex elements transparent. Like an icon of a complex shape - the best you can do is encase it in a circle but it will be an opaque circle.

If you absolutely MUST make something transparent - there is a workaround you can implement. Namely, you can display your transparent elements in the second transparent jFrame that sits on top of the first one. Set JFrame type to Undecorated, make all elements on it (except the one you need to show Opaque=false, set the JFrame's background to Color(1,1,1,0), where 0 is alpha. I.e. transparent. This is not at all an elegant solution, but hey - an option is still better than nothing.
25
Lightweight Java Gaming Library / Re: BGFX: 'Failed to create swap chain'
« Last post by mangledpixel on December 17, 2019, 17:43:40 »
Never mind, I figured it out. For future reference: you need to set the platformdata's nwh field to the native window handle of a valid window (doesn't matter which one) before trying to create framebuffers.
26
Lightweight Java Gaming Library / BGFX: 'Failed to create swap chain'
« Last post by mangledpixel on December 15, 2019, 16:58:47 »
I'm trying to create a BGFX frame buffer from a window created using GLFW, using bgfx_create_frame_buffer_from_nwh, but this always results in the error Fatal error 2: Failed to create swap chain. C:\projects\bgfx\src\renderer_d3d11.cpp line 4632 being thrown from the external BGFX thread (I set up a custom callback to catch it). The ultimate aim here is to create buffers for multiple windows, but this also fails in the case of a single window.
 
The relevant code:
Code: [Select]
long nwh;
switch (Platform.get()) {
case LINUX: nwh = GLFWNativeX11.glfwGetX11Window(window); break;
case MACOSX: nwh = GLFWNativeCocoa.glfwGetCocoaWindow(window); break;
case WINDOWS: nwh = GLFWNativeWin32.glfwGetWin32Window(window); break;
default: nwh = NULL; break;
}
log("Creating framebuffer for view "+view+" with window handle "+nwh);
short frameBuffer = bgfx_create_frame_buffer_from_nwh(nwh, width, height, BGFX_TEXTURE_FORMAT_BGRA8, BGFX_TEXTURE_FORMAT_D24S8);

This is after calling bgfx_set_platform_data and bgfx_init, and after the GLFW window has been created.

Getting capabilities from BGFX shows true for BGFX_CAPS_SWAP_CHAIN and for BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER on the relevant format(s). Not sure what I'm doing wrong here, or if this is even the correct approach for rendering to multiple GLFW windows with BGFX.
27
OpenGL / Re: JAWT - getting drawing surface from jPanel
« Last post by Aisaaax on December 13, 2019, 04:15:18 »
in Swing, jFrame seems to be a heavyweight component. My routine seems to generate valid code and surfaces and whatnot.
But somehow I can't render directly to jFrame as I can to a Canvas. Why?
28
Lightweight Java Gaming Library / Re: How to do physics
« Last post by KaiHH on December 11, 2019, 09:45:49 »
29
Lightweight Java Gaming Library / How to do physics
« Last post by Kgboi on December 11, 2019, 00:25:48 »
I'm at the point in my game where I want to include physics, however I noticed LWJGL doesn't come with a physics library. Anyone know any way to do physics without writing my own physcics engine?
30
Lightweight Java Gaming Library / need help, some things dont render.
« Last post by matyklug on December 10, 2019, 18:18:01 »
my code: https://gist.github.com/matyklugDebbuged/91ff4aca9db683b9c06ca747d8e8bb1e
it should render a textured cube. the code in Main.java is the thing i call for rendering the cube, but it doesnt render anything. other stuff renders okay. even stuff using the same renderer.

EDIT: fixed, i wasnt reseting the index...
Pages: 1 2 [3] 4 5 ... 10