Hello Guest

Recent Posts

Pages: 1 ... 8 9 [10]
91
I was hoping somebody could give me a clue what I am doing wrong when creating character bitmaps from the STBTruetype library. The generated bitmap seems to be a bitmap representing the character requested, however it is in a 4x4 grid with a slight offset in the negative x asix for each row. I thought I would get back a bitmap representing a single instance of the character. Here is the output for the character 'A':



Hopefully this code sample isn't too bad:

Font.java
Code: [Select]
public class Font {
private STBTTFontinfo info;
private float pixelScale;

public Font(final String ttfPath) throws IOException {
final ByteBuffer ttfBuffer = ResourceLoader.toByteBuffer(ttfPath);
info = STBTTFontinfo.create();
stbtt_InitFont(info, ttfBuffer, 0);
pixelScale = stbtt_ScaleForPixelHeight(info, 512);
}

public Character getChar(final char c) {
final int[] w = new int[]{0}, h = new int[]{0}, xoff = new int[]{0}, yoff = new int[]{0};
final ByteBuffer bitmapData = stbtt_GetCodepointBitmap(info, 0, pixelScale, c, w, h, xoff, yoff);
return new Character(bitmapData, w[0], h[0], xoff[0], yoff[0]); // dumb pojo to hold bitmap and dimensions
}
}

FontText.java
Code: [Select]
public class FontTest {
private Window window = RunnerUtils.setupWindow();
private Font font;

public static void main(String[] args) throws Exception {
new FontTest().run();
}

private void run() throws Exception {
OpenGlState.init(window);
font = new Font("font/roboto/Roboto-Black.ttf");

Character aChar = font.getChar('A');
int textureId = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, aChar.getWidth(), aChar.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, aChar.getBitmapData());

OpenglUtils.saveTextureToJpg(textureId, new File("out.png")); // Saves to file, but rendering the bitmap to a quad is the same image

window.destroy();
}
}
92
Lightweight Java Gaming Library / Re: A question about LWJGL.
« Last post by overlisted on November 27, 2019, 18:49:40 »
Modern OpenGL gives you ability to do very cool tricks (and much more performance) if you understand it.
Do you want to get some classes that makes modern OpenGL object-oriented? They was made by me.

The best modern OpenGL tutorial (it's easy to read it being a java dev): learnopengl.com. You can begin learning from "'Hello Window" page. Also don't forget to replace GLM classes with JOML's ones (mat4 = Matrix4f, vec3 = Vector3f)

btw, do you understand the matrix (vector) math? If you don't it will be very hard to use OpenGL


Sorry for my bad English if it is. It is so hard to talk about math and GL in not your native language.
93
OpenGL / Re: Existing uniform not found
« Last post by KaiHH on November 26, 2019, 22:05:59 »
Only instructions that any fragment shader output depends on (transitively) remains in the shader.
That also means that potentially whole functions are removed iff there is no instructions dependency path from a fragment shader output back to a call of this function.
So simply start at a fragment shader output write instructions (such as gl_FragColor or any `out` variable) and walk your way backwards to all instructions / code paths this output write instruction depends on and the transitive closure (dependencies of those dependencies) of this. Every instruction (and also uniform delcaration) that you did not visit via this algorithm will be removed.
94
OpenGL / Re: Existing uniform not found
« Last post by Zekutsu on November 26, 2019, 21:54:43 »
If you mean this shader, then the reason is that the OpenGL GLSL compiler agressively optimizes/removes unused uniforms. It does via checking whether there is any dependency graph from any output of the fragment shader to a uniform. And this dependency does not exist, because ultimately in line 170, the variable `currNormal` is not being used to produce a fragment output.

Ok so, for what I understood, even if the actual uniform (normalMap) is used inside a function but the end result of the latter is not used, all the "stuff" that is used, and only used, there will just be removed?


EDIT

GOD currNormal was not actually used in the row below and that was causing all the problem.

Man THANK YOU SO MUCH, I spent hours trying to fix it looking through the whole project!
95
OpenGL / Re: Existing uniform not found
« Last post by KaiHH on November 26, 2019, 12:09:06 »
If you mean this shader, then the reason is that the OpenGL GLSL compiler agressively optimizes/removes unused uniforms. It does via checking whether there is any dependency graph from any output of the fragment shader to a uniform. And this dependency does not exist, because ultimately in line 170, the variable `currNormal` is not being used to produce a fragment output.
96
OpenGL / Existing uniform not found
« Last post by Zekutsu on November 26, 2019, 11:01:32 »
Hi,

I've added a new uniform to a fragment shader (to implement normal mapping), but it just can't find it (the specific uniform is "normalMap").

Here's the code:

https://github.com/CristianCamillo/LWJGL-3-Guide

Why can't it be located?

Thank you in advance.
97
General Java Game Development / Re: 'compile on save' - Apache Netbeans 10 ?
« Last post by sc on November 22, 2019, 17:29:54 »
OK. I think I have it working now ...
If anyone is interested :

* project > properties > compile : Compile on save = OFF
* tools > options > java > debugger > general : Apply code changes after save = OFF

After you make some code changes : save the file. Press 'apply code changes' button (3 green squares next to 'run to cursor' button) ... et voila !

Remember :
* ONLY for code that is referenced in main game loop !!!!!
* ONLY for code that is running in debug mode !!!!!
* ONLY for modification of existing methods (no new method, new variable, new class creation) !!!!!

I am using Apache NetBeans 11 with OpenJDK 11 (proj > props > libr : JDK11), but it will most likely work for older versions as well.

98
General Java Game Development / Re: 'compile on save' - Apache Netbeans 10 ?
« Last post by sc on November 22, 2019, 12:06:23 »
I've tried different places, but all inside methods.
For instance, I tried changing the glClearColor() in the render method.
99
General Java Game Development / Re: 'compile on save' - Apache Netbeans 10 ?
« Last post by KaiHH on November 22, 2019, 11:21:20 »
Where exactly do you "change position of a game item". What exactly do you mean by that.
HotSwap can only change the code in a method or constructor.
100
General Java Game Development / [solved] 'compile on save' - Apache Netbeans 10 ?
« Last post by sc on November 22, 2019, 09:20:23 »
I'm trying to use hot code swap, so that I don't have to restart my entire application when I make small changes to the code ... but it doesn't seem to work.

This is what I have tried so far :
* project > properties > compile : Compile on save=ON
* tools > options > java > debugger > general : apply code changes after save=ON
* run project in debug mode, with or without breakpoints
* change position of a game item, change color of a lamp > save > no effect inside the game window ...

* I also tried 'HotSwapAgent' (http://hotswapagent.org/)

Anybody have any ideas ??? It seems simple enough, but maybe I'm doing something wrong ?
Pages: 1 ... 8 9 [10]