Trouble Compiling Raylib-J to jar file
BlueFalcon234 opened this issue · 6 comments
I am trying to compile the current main branch of Raylib-J library to a jar file, so that I can use that jar file in a another project, however the compiled jar file is not working.
Here’s what I did:
Downloaded the repo to my system, and opened it up with IntelliJ.
Then I went on build, build artifact, build jar.
It built the jar file, but once I import that jar file to my other project I’m working on, it doesn’t recognize any Raylib/Raylib-J methods.
I am new to IntelliJ, so it’s most likely I’m missing something, any help would be great.
Hi, the issue was the build configuration in the repo was not including the Raylib-J compile output to the .jar
You can fix it by adjusting the build config, or by pulling the latest changes from the repo
Hey there,
After cloning this repo after the update, I added the project root folder as the content root in Project Structure-Modules, then try to build the jar again, but again it did not work. Leading to the same results of no methods being recognize. However I then went on Project Structure, Libraries, then deleted the "native" library containing the lwjgl framework, then re-added back in the "native" library. That seem to work as after rebuilding, then importing that raylib-j jar to my project, the methods are now recognize as there no longer highlighted red. My test project then compile and ran fine. I don't know if doing this was the right way but it seemed to work.
The only thing is that for some reason texture image don't draw on screen, shapes loaded fine. I can see the code itself doesn't have any error, and the log says the image loaded successfully. I can't tell if I accidently l messed something up while trying to compile the raylib-j library, or if it's due to something else.
(EDIT: I already know that using raylib-j_0.4 the texture loads fine, so then I try to then use to pre-compile raylib-J_DEV-0.5 to see if the texture would load, but the texture also did not load. Could it be a bug from DEV-0.5? Using a Windows Machine by the way.)
Thanks for all your help by the way CreedVI :)
I've been using 0.5_DEV for my personal project and have had no issues with loading textures.
Can you share more details about your code?
Yep no problem. Here's my test code, it's a modified version of the keyboard Input example, just testing a bunch of things.
The Test Code:
import com.raylib.java.Raylib;
import com.raylib.java.core.Color;
//import com.raylib.java.core.camera.Camera2D;
import com.raylib.java.core.rcamera.Camera2D;
import com.raylib.java.core.input.Keyboard;
import com.raylib.java.core.input.Mouse;
import com.raylib.java.core.rCore;
import com.raylib.java.raymath.Vector2;
import com.raylib.java.shapes.Rectangle;
import com.raylib.java.textures.rTextures;
import com.raylib.java.textures.*;
import com.raylib.java.raymath.Raymath;
//import static com.raylib.java.core.input.Keyboard.*;
/*******************************************************************************************
*
* raylib-j [core] example - Keyboard input
*
* This example has been created using raylib-j (Version 0.4)
* Ported by CreedVI
* https://github.com/creedvi/raylib-j
*
* raylib is licensed under an unmodified zlib/libpng license
* Original example written and copyright by Ramon Santamaria (@raysan5)
* https://github.com/raysan5
*
********************************************************************************************/
public class Main{
public static void main(String[] args){
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
Raylib rlj = new Raylib();
rlj.core.InitWindow(screenWidth, screenHeight, "raylib-j [core] example - keyboard input");
//Image icon = rTextures.LoadImage("resources/raylib-j_logo.png");
//rlj.core.SetWindowIcon(icon); //also couldn't get icon to set window icon
Texture2D picture = rTextures.LoadTexture("resources/raylib-j_logo.png");
Vector2 ballPosition = new Vector2((float) screenWidth / 2, (float) screenHeight / 2);
Vector2 imageSize = new Vector2(rlj.core.GetMouseX(), rlj.core.GetMouseY());
Vector2 mousePos = new Vector2(rlj.core.GetMouseX(), rlj.core.GetMouseY());
Camera2D camera = new Camera2D();
camera.target = new Vector2(ballPosition.getX(), ballPosition.getY());
camera.offset = new Vector2(screenWidth / 2.0f, screenHeight / 2.0f);
camera.rotation = 0.0f;
camera.zoom = 1.0f;
int drawBlock = 0;
int xPos = 0;
int yPos = 0;
rlj.core.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!rlj.core.WindowShouldClose()){ // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
if (rCore.IsKeyDown(Keyboard.KEY_RIGHT)){
ballPosition.x += 2.0f;
}
if (rCore.IsKeyDown(Keyboard.KEY_LEFT)){
ballPosition.x -= 2.0f;
}
if (rCore.IsKeyDown(Keyboard.KEY_UP)){
ballPosition.y -= 2.0f;
}
if (rCore.IsKeyDown(Keyboard.KEY_DOWN)){
ballPosition.y += 2.0f;
}
imageSize.setY((float)(rlj.core.GetMouseY()));
imageSize.setX((float)(rlj.core.GetMouseX()));
mousePos.setY((float)(rlj.core.GetMouseY()));
mousePos.setX((float)(rlj.core.GetMouseX()));
Vector2 stw = rlj.core.GetScreenToWorld2D(mousePos, camera);
//rlj.text.DrawText("xPos: " + mousePos.getX(), 200, 0, 10, Color.GREEN);
//rlj.text.DrawText("yPos: " + mousePos.getY(), 300, 0, 10, Color.GREEN);
rlj.text.DrawText("x: " + rlj.core.GetMouseX(), 200, 0, 10, Color.GREEN);
rlj.text.DrawText("y: " + rlj.core.GetMouseY(), 300, 0, 10, Color.GREEN);
rlj.text.DrawText("xBall: " + ballPosition.getX(), 400, 0, 10, Color.GREEN);
rlj.text.DrawText("yBall: " + ballPosition.getY(), 500, 0, 10, Color.GREEN);
rlj.text.DrawText("xRec: " + stw.getX(), 600, 0, 10, Color.GREEN);
rlj.text.DrawText("yRec: " + stw.getY(), 700, 0, 10, Color.GREEN);
//camera.target = new Vector2(ballPosition.getX(), ballPosition.getY());
// Translate based on mouse right click
if (rCore.IsMouseButtonDown(Mouse.MouseButton.MOUSE_BUTTON_MIDDLE))
{
Vector2 delta = rlj.core.GetMouseDelta();
delta = Raymath.Vector2Scale(delta, -1.0f/camera.zoom);
camera.target = Raymath.Vector2Add(camera.target, delta);
}
// Zoom based on mouse wheel
float wheel = rCore.GetMouseWheelMove();
if (wheel != 0)
{
// Get the world point that is under the mouse
Vector2 mouseWorldPos = rlj.core.GetScreenToWorld2D(rCore.GetMousePosition(), camera);
// Set the offset to where the mouse is
camera.offset = rCore.GetMousePosition();
// Set the target to match, so that the camera maps the world space point
// under the cursor to the screen space point under the cursor at any zoom
camera.target = mouseWorldPos;
// Zoom increment
final float zoomIncrement = 0.125f;
camera.zoom += (wheel*zoomIncrement);
if (camera.zoom < zoomIncrement)
{
camera.zoom = zoomIncrement;
}
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rlj.core.BeginDrawing();
rlj.core.ClearBackground(Color.RAYWHITE);
rlj.core.BeginMode2D(camera);
rlj.shapes.DrawRectangle(200,400,50,50, Color.DARKGREEN);
rlj.shapes.DrawCircleV(ballPosition, 50, Color.MAROON);
ballPosition.setY(ballPosition.getY() + 1.0f);
//couldn't get texture to load in DEV0.5 and in compiled jar of the newest reversion main branch, works on 0.4
rlj.textures.DrawTexture(picture, 45, 50, Color.WHITE);
Rectangle box = new Rectangle(xPos, yPos, 50, 50);
if(drawBlock == 1)
{
rlj.shapes.DrawRectangle(xPos, yPos, 50, 50, Color.DARKGRAY);
}
if(rCore.IsMouseButtonDown(Mouse.MouseButton.MOUSE_BUTTON_LEFT))
{
drawBlock = 1;
xPos = (int)stw.getX();
yPos = (int)stw.getY();
}
else if (rCore.IsMouseButtonDown(Mouse.MouseButton.MOUSE_BUTTON_RIGHT) && rlj.shapes.CheckCollisionPointRec(stw, box))
{
drawBlock = 0;
}
//rlj.shapes.DrawRectangle((int)(stw.getX()), (int)(stw.getY()), 20, 20, Color.VIOLET);
rlj.core.EndMode2D();
rlj.text.DrawText("move the ball with arrow keys", 10, 10, 20, Color.DARKGRAY);
//rlj.textures.DrawTextureEx(picture, imageSize, 0f, 0.1f, Color.WHITE);
rlj.text.DrawText("FPS: " + Integer.toString(rCore.GetFPS()), 3, 0, 10, Color.GREEN);
rlj.core.EndDrawing();
//----------------------------------------------------------------------------------
}
}
}
In regards to your code, I'm assuming the texture you're loading is the Raylib-J logo from the repo, so in my test I used the 128x128.
For the Window Icon glfw requires an image with 32-bit colour resolution, so the Raylib-J logo won't work (for now - I'm going to look into fixing that); I substituted the icon texture with one of my personal assets for the test.
For the texture, I created a new project, pasted your code in, added the resources
directory as a resources module in my project structure. (File > Project Structure > Module - - See Image 1)
Ah I see, Thank you so much. I was able to fix the issue by what you said, by marking my resources folder as "resources", in the project structure settings. I thought I had it marked as that, but I guess not, as it was working fine with 0.4. Both now the texture is being drawn on to the screen, as well as the icon is now showing as well.
Again, thanks for the help.