New bitmap character single-character widget
This commit is contained in:
parent
02ded35c06
commit
b3f66c60da
18
assets/Shaders/font/bitmapchar/bitmapchar.fs
Normal file
18
assets/Shaders/font/bitmapchar/bitmapchar.fs
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D screenTexture;
|
||||
uniform vec3 color;
|
||||
|
||||
void main(){
|
||||
vec3 textColorModifier = color;
|
||||
if(color.x == 0 && color.y == 0 && color.z == 0){
|
||||
textColorModifier.x = 1;
|
||||
textColorModifier.y = 1;
|
||||
textColorModifier.z = 1;
|
||||
}
|
||||
FragColor = texture(screenTexture, TexCoords) * vec4(textColorModifier.xyz, 1.0);
|
||||
}
|
||||
29
assets/Shaders/font/bitmapchar/bitmapchar.vs
Normal file
29
assets/Shaders/font/bitmapchar/bitmapchar.vs
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
#version 330 core
|
||||
layout (location = 0) in vec2 aPos;
|
||||
layout (location = 4) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform vec3 mPosition;
|
||||
uniform vec3 mDimension;
|
||||
uniform vec3 tPosition;
|
||||
uniform vec3 tDimension;
|
||||
|
||||
void main(){
|
||||
|
||||
|
||||
vec2 finalPos = vec2(
|
||||
((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1,
|
||||
((1-(aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1
|
||||
// aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y)
|
||||
);
|
||||
gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0);
|
||||
|
||||
|
||||
vec2 finalTex = vec2(
|
||||
aTexCoords.x * tDimension.x + tPosition.x,
|
||||
aTexCoords.y * tDimension.y + tPosition.y
|
||||
);
|
||||
TexCoords = finalTex;
|
||||
}
|
||||
@ -8,4 +8,5 @@ public class AssetDataStrings {
|
||||
public static final String ASSET_STRING_BITMAP_FONT = "bitmapFont";
|
||||
public static final String ASSET_STRING_BITMAP_FONT_MESH_NAME = "quad";
|
||||
public static final String ASSET_STRING_SKYBOX_BASIC = "skyboxBasic";
|
||||
public static final String BITMAP_CHARACTER_MODEL = "bitmapCharacterModel";
|
||||
}
|
||||
|
||||
@ -337,6 +337,7 @@ public class Globals {
|
||||
materialDefault.set_specular("Textures/default_specular.png");
|
||||
//create default lights
|
||||
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
|
||||
assetManager.registerModelToSpecificString(ModelUtils.createBitmapCharacter(), AssetDataStrings.BITMAP_CHARACTER_MODEL);
|
||||
RawFontMap fontMap = FileUtils.loadObjectFromAssetPath("Textures/Fonts/myFontMap.json", RawFontMap.class);
|
||||
FontUtils.setFontDataMap(fontMap);
|
||||
//particle billboard model
|
||||
|
||||
@ -688,4 +688,110 @@ public class ModelUtils {
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static Model createBitmapCharacter(){
|
||||
|
||||
Model rVal = new Model();
|
||||
rVal.meshes = new ArrayList();
|
||||
Mesh m = new Mesh();
|
||||
m.vertexArrayObject = glGenVertexArrays();
|
||||
glBindVertexArray(m.vertexArrayObject);
|
||||
//vertices
|
||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(12);
|
||||
VertexArrayBufferData.put( 0);
|
||||
VertexArrayBufferData.put( 1);
|
||||
|
||||
VertexArrayBufferData.put( 0);
|
||||
VertexArrayBufferData.put( 0);
|
||||
|
||||
VertexArrayBufferData.put( 1);
|
||||
VertexArrayBufferData.put( 0);
|
||||
|
||||
VertexArrayBufferData.put( 0);
|
||||
VertexArrayBufferData.put( 1);
|
||||
|
||||
VertexArrayBufferData.put( 1);
|
||||
VertexArrayBufferData.put( 0);
|
||||
|
||||
VertexArrayBufferData.put( 1);
|
||||
VertexArrayBufferData.put( 1);
|
||||
VertexArrayBufferData.flip();
|
||||
|
||||
|
||||
IntBuffer faceArrayBufferData = BufferUtils.createIntBuffer(6);
|
||||
faceArrayBufferData.put(0);
|
||||
faceArrayBufferData.put(1);
|
||||
faceArrayBufferData.put(2);
|
||||
|
||||
faceArrayBufferData.put(3);
|
||||
faceArrayBufferData.put(4);
|
||||
faceArrayBufferData.put(5);
|
||||
faceArrayBufferData.flip();
|
||||
|
||||
|
||||
|
||||
//texture coords
|
||||
FloatBuffer TextureArrayBufferData = BufferUtils.createFloatBuffer(12);
|
||||
TextureArrayBufferData.put(0);
|
||||
TextureArrayBufferData.put(1);
|
||||
|
||||
TextureArrayBufferData.put(0);
|
||||
TextureArrayBufferData.put(0);
|
||||
|
||||
TextureArrayBufferData.put(1);
|
||||
TextureArrayBufferData.put(0);
|
||||
|
||||
TextureArrayBufferData.put(0);
|
||||
TextureArrayBufferData.put(1);
|
||||
|
||||
TextureArrayBufferData.put(1);
|
||||
TextureArrayBufferData.put(0);
|
||||
|
||||
TextureArrayBufferData.put(1);
|
||||
TextureArrayBufferData.put(1);
|
||||
TextureArrayBufferData.flip();
|
||||
|
||||
|
||||
//buffer vertices
|
||||
m.buffer_vertices(VertexArrayBufferData, 2);
|
||||
//buffer normals
|
||||
m.buffer_normals(VertexArrayBufferData, 2);
|
||||
//buffer faces
|
||||
m.buffer_faces(faceArrayBufferData);
|
||||
//buffer texture coords
|
||||
m.buffer_texture_coords(TextureArrayBufferData, 2);
|
||||
|
||||
|
||||
m.shader = ShaderProgram.loadSpecificShader("/Shaders/font/bitmapchar/bitmapchar.vs", "/Shaders/font/bitmapchar/bitmapchar.fs");
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
m.parent = rVal;
|
||||
m.nodeID = AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME;
|
||||
|
||||
Material uiMat = new Material();
|
||||
Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png");
|
||||
uiMat.set_diffuse("/Textures/Fonts/myfont1-harsher.png");
|
||||
uiMat.set_specular("/Textures/Fonts/myfont1-harsher.png");
|
||||
m.setMaterial(uiMat);
|
||||
rVal.materials = new ArrayList();
|
||||
rVal.materials.add(uiMat);
|
||||
|
||||
rVal.meshes.add(m);
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package electrosphere.renderer.ui;
|
||||
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.ui.font.TextBox;
|
||||
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
|
||||
import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable;
|
||||
import electrosphere.renderer.ui.widgets.ImagePanel;
|
||||
import electrosphere.renderer.ui.widgets.TextInput;
|
||||
@ -81,16 +82,20 @@ public class WidgetUtils {
|
||||
// imagePanel.setPositionY(50);
|
||||
// imagePanel.setVisible(true);
|
||||
// rVal.addWidget(imagePanel);
|
||||
TextInput textInput = new TextInput();
|
||||
textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
|
||||
textInput.setPositionX(0);
|
||||
textInput.setPositionY(0);
|
||||
textInput.setWidth(500);
|
||||
textInput.setHeight(500);
|
||||
textInput.setFontWidth(10);
|
||||
textInput.setFontHeight(27);
|
||||
textInput.setVisible(true);
|
||||
rVal.addWidget(textInput);
|
||||
// TextInput textInput = new TextInput();
|
||||
// textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
|
||||
// textInput.setPositionX(0);
|
||||
// textInput.setPositionY(0);
|
||||
// textInput.setWidth(500);
|
||||
// textInput.setHeight(500);
|
||||
// textInput.setFontWidth(10);
|
||||
// textInput.setFontHeight(27);
|
||||
// textInput.setVisible(true);
|
||||
// rVal.addWidget(textInput);
|
||||
|
||||
|
||||
BitmapCharacter characterDisp = new BitmapCharacter(0,-50,500,500,'A');
|
||||
rVal.addWidget(characterDisp);
|
||||
|
||||
// TextInput textInput2 = new TextInput();
|
||||
// textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
package electrosphere.renderer.ui.font.bitmapchar;
|
||||
|
||||
import electrosphere.engine.assetmanager.AssetDataStrings;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.Model;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.font.FontUtils;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author satellite
|
||||
*/
|
||||
public class BitmapCharacter extends Widget {
|
||||
|
||||
int positionX;
|
||||
int positionY;
|
||||
int width;
|
||||
int height;
|
||||
String text;
|
||||
|
||||
Vector3f color = new Vector3f(0,0,0);
|
||||
|
||||
|
||||
|
||||
public BitmapCharacter(int posX, int posY, int width, int height, char toDraw){
|
||||
positionX = posX;
|
||||
positionY = posY;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
text = "" + toDraw;
|
||||
}
|
||||
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void setColor(Vector3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight){
|
||||
Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer);
|
||||
Globals.renderingEngine.setViewportSize(parentWidth, parentHeight);
|
||||
float ndcX = (float)positionX/parentWidth;
|
||||
float ndcY = (float)positionY/parentHeight;
|
||||
float ndcWidth = (float)width/parentWidth;
|
||||
float ndcHeight = (float)height/parentHeight;
|
||||
// System.out.println(ndcX + " " + ndcY + " " + ndcWidth + " " + ndcHeight);
|
||||
//monowidth for the moment
|
||||
// float charWidth = ndcWidth/cols;
|
||||
// float charHeight = ndcHeight/rows;
|
||||
char toDraw = text.charAt(0);
|
||||
Vector3f characterPosition = new Vector3f(ndcX,ndcY,0);
|
||||
Vector3f characterDimensions = new Vector3f(ndcWidth,ndcHeight,0);
|
||||
Vector3f bitMapPosition = FontUtils.getPositionOfCharacter(toDraw);
|
||||
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacter(toDraw);
|
||||
Model charModel = Globals.assetManager.fetchModel(AssetDataStrings.BITMAP_CHARACTER_MODEL);
|
||||
if(charModel != null && toDraw != ' '){
|
||||
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mPosition", characterPosition);
|
||||
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mDimension", characterDimensions);
|
||||
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tPosition", bitMapPosition);
|
||||
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tDimension", bitMapDimension);
|
||||
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "color", color);
|
||||
charModel.drawUI();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user