the UI update part 1

This commit is contained in:
austin 2021-10-23 10:10:16 -04:00
parent cc2709aa93
commit 9fdb9a23c0
27 changed files with 592 additions and 131 deletions

View File

@ -0,0 +1,10 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D screenTexture;
void main(){
FragColor = texture(screenTexture, TexCoords);
}

View File

@ -0,0 +1,29 @@
#version 330 core
layout (location = 0) in vec3 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 * mDimension.x - (1 - mDimension.x) + mPosition.x,
aPos.y * mDimension.y + (1 - mDimension.y) - mPosition.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
);
// vec2 finalTex = aTexCoords;
// vec2 finalTex = vec2(
// aTexCoords.x + 0.7,
// aTexCoords.y
// );
TexCoords = finalTex;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -86,7 +86,7 @@ public class LoadingThread extends Thread {
Globals.currentMenu = MenuUtils.createTitleMenu(); Globals.currentMenu = MenuUtils.createTitleMenu();
loadingBox.setDraw(false); loadingBox.setVisible(false);
MenuUtils.makeMenuDrawable(Globals.currentMenu); MenuUtils.makeMenuDrawable(Globals.currentMenu);
@ -102,7 +102,7 @@ public class LoadingThread extends Thread {
case LOAD_MAIN_GAME: case LOAD_MAIN_GAME:
loadingBox.setDraw(true); loadingBox.setVisible(true);
//disable menu input //disable menu input
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT); Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
@ -162,7 +162,7 @@ public class LoadingThread extends Thread {
Globals.controlHandler.hideMouse(); Globals.controlHandler.hideMouse();
loadingBox.setDraw(false); loadingBox.setVisible(false);
RenderUtils.recaptureScreen(); RenderUtils.recaptureScreen();
@ -187,7 +187,7 @@ public class LoadingThread extends Thread {
case LOAD_ARENA: case LOAD_ARENA:
loadingBox.setDraw(true); loadingBox.setVisible(true);
//disable menu input //disable menu input
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT); Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
@ -242,7 +242,7 @@ public class LoadingThread extends Thread {
//hide cursor //hide cursor
Globals.controlHandler.hideMouse(); Globals.controlHandler.hideMouse();
loadingBox.setDraw(false); loadingBox.setVisible(false);
RenderUtils.recaptureScreen(); RenderUtils.recaptureScreen();
@ -544,14 +544,14 @@ public class LoadingThread extends Thread {
//// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0)); //// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
// } // }
// Random rand = new Random(); Random rand = new Random();
// for(int i = 0; i < 1000; i++){ for(int i = 0; i < 1000; i++){
// String wheatPath = "Models/wheat2.fbx"; String wheatPath = "Models/wheat2.fbx";
// Entity wheatStalk = EntityUtils.spawnDrawableEntity(wheatPath); Entity wheatStalk = EntityUtils.spawnDrawableEntity(wheatPath);
// EntityUtils.getPosition(wheatStalk).set(rand.nextFloat() * 20, 0, rand.nextFloat() * 20); EntityUtils.getPosition(wheatStalk).set(rand.nextFloat() * 20, 0, rand.nextFloat() * 20);
// EntityUtils.getRotation(wheatStalk).rotateLocalX(-(float)Math.PI/2.0f); EntityUtils.getRotation(wheatStalk).rotateLocalX(-(float)Math.PI/2.0f);
// EntityUtils.getScale(wheatStalk).set(1, 1, 2); EntityUtils.getScale(wheatStalk).set(1, 1, 2);
// } }
// String buildingPath = "Models/building1.fbx"; // String buildingPath = "Models/building1.fbx";
// Entity building = EntityUtils.spawnDrawableEntity(buildingPath); // Entity building = EntityUtils.spawnDrawableEntity(buildingPath);

View File

@ -173,6 +173,9 @@ public class Globals {
public static Material materialDefault; public static Material materialDefault;
public static String blackTexture; public static String blackTexture;
public static String testingTexture;
public static String planeModelID;
public static ArrayList<PointLight> lightPointListDefault; public static ArrayList<PointLight> lightPointListDefault;
public static SpotLight lightSpotDefault; public static SpotLight lightSpotDefault;
@ -328,7 +331,7 @@ public class Globals {
particleBillboardModel = assetManager.registerModel(RenderUtils.createParticleModel()); particleBillboardModel = assetManager.registerModel(RenderUtils.createParticleModel());
//black texture for backgrouns //black texture for backgrouns
blackTexture = "Textures/b1.png"; blackTexture = "Textures/b1.png";
Globals.assetManager.addTexturePathtoQueue("Textures/b1.png"); Globals.assetManager.addTexturePathtoQueue(blackTexture);
//loading box //loading box
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true); loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
//init default shaderProgram //init default shaderProgram
@ -345,6 +348,13 @@ public class Globals {
assetManager.addModelPathToQueue("Models/unitcylinder.fbx"); assetManager.addModelPathToQueue("Models/unitcylinder.fbx");
assetManager.addModelPathToQueue("Models/unitplane.fbx"); assetManager.addModelPathToQueue("Models/unitplane.fbx");
assetManager.addModelPathToQueue("Models/unitcube.fbx"); assetManager.addModelPathToQueue("Models/unitcube.fbx");
planeModelID = assetManager.registerModel(RenderUtils.createPlaneModel());
//init ui images
assetManager.addTexturePathtoQueue("Textures/ui/WindowBorder.png");
testingTexture = "Textures/Testing1.png";
Globals.assetManager.addTexturePathtoQueue(testingTexture);
//as these assets are required for the renderer to work, we go ahead and //as these assets are required for the renderer to work, we go ahead and
//load them into memory now. The loading time penalty is worth it I think. //load them into memory now. The loading time penalty is worth it I think.

View File

@ -18,6 +18,7 @@ public class Menu {
MULTIPLAYER_MENU, MULTIPLAYER_MENU,
IP_MENU, IP_MENU,
OPTIONS_MAIN_MENU, OPTIONS_MAIN_MENU,
TEST,
} }
MenuType type; MenuType type;

View File

@ -44,6 +44,11 @@ public class MenuTransition {
m.dispose(); m.dispose();
Globals.currentMenu = MenuUtils.createOptionsMainMenu(); Globals.currentMenu = MenuUtils.createOptionsMainMenu();
break; break;
//test
case 4:
m.dispose();
Globals.currentMenu = MenuUtils.createTestMainMenu();
break;
} }
break; break;
case MULTIPLAYER_MENU: case MULTIPLAYER_MENU:
@ -106,6 +111,10 @@ public class MenuTransition {
m.dispose(); m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu(); Globals.currentMenu = MenuUtils.createTitleMenu();
break; break;
case TEST:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
} }
} }

View File

@ -24,7 +24,7 @@ public class MenuUtils {
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "MULTIPLAYER", true)); rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "MULTIPLAYER", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "ARENA", true)); rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "ARENA", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "OPTIONS", true)); rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "OPTIONS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "UI TESTING", true)); rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 425, "UI TESTING", true));
return rVal; return rVal;
} }
@ -61,15 +61,21 @@ public class MenuUtils {
return rVal; return rVal;
} }
public static Menu createTestMainMenu(){
Menu rVal = new Menu(MenuType.TEST);
rVal.addElement(WidgetUtils.createWindowTEST());
return rVal;
}
public static void makeMenuDrawable(Menu m){ public static void makeMenuDrawable(Menu m){
for(Widget w : m.widgetList){ for(Widget w : m.widgetList){
w.setDraw(true); w.setVisible(true);
} }
} }
public static void makeMenuUndrawable(Menu m){ public static void makeMenuUndrawable(Menu m){
for(Widget w : m.widgetList){ for(Widget w : m.widgetList){
w.setDraw(false); w.setVisible(false);
} }
} }

View File

@ -10,15 +10,25 @@ import electrosphere.renderer.texture.Texture;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.assimp.AIMaterial; import org.lwjgl.assimp.AIMaterial;
import org.lwjgl.assimp.AIMaterialProperty; import org.lwjgl.assimp.AIMaterialProperty;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
import static org.lwjgl.opengl.GL13.glActiveTexture;
/** /**
* *
* @author amaterasu * @author amaterasu
*/ */
public class Material { public class Material {
String diffuse; String diffuse;
String specular; String specular;
boolean hasTransparency = false; boolean hasTransparency = false;
boolean usesFetch = true;
int texturePointer;
public Material(){ public Material(){
} }
@ -53,14 +63,25 @@ public class Material {
// } // }
} }
public void setTexturePointer(int pointer){
texturePointer = pointer;
usesFetch = false;
}
public void apply_material(){ public void apply_material(){
Texture diffuseTexture = Globals.assetManager.fetchTexture(diffuse); //basically a switch for the case where we want to manually set texture pointer
if(diffuseTexture != null){ if(usesFetch){
diffuseTexture.bind(0); Texture diffuseTexture = Globals.assetManager.fetchTexture(diffuse);
} if(diffuseTexture != null){
Texture specularTexture = Globals.assetManager.fetchTexture(specular); diffuseTexture.bind(0);
if(specularTexture != null){ }
specularTexture.bind(1); Texture specularTexture = Globals.assetManager.fetchTexture(specular);
if(specularTexture != null){
specularTexture.bind(1);
}
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texturePointer);
} }
} }
public void apply_material(int diffuse_channel, int specular_channel){ public void apply_material(int diffuse_channel, int specular_channel){

View File

@ -608,7 +608,7 @@ public class Mesh {
textureListArrayUniformName = uniformName; textureListArrayUniformName = uniformName;
} }
public void set_material(Material input){ public void setMaterial(Material input){
this.material = input; this.material = input;
} }

View File

@ -362,6 +362,12 @@ public class Model {
} }
} }
public void drawFramebuffer(){
for(Mesh m : meshes){
m.complexDraw(true, false, true, false, false, false, false);
}
}
public void pushUniformToMesh(String meshName, String uniformKey, Object uniform){ public void pushUniformToMesh(String meshName, String uniformKey, Object uniform){
for(Mesh m : meshes){ for(Mesh m : meshes){
if(m.nodeID.equals(meshName)){ if(m.nodeID.equals(meshName)){

View File

@ -334,7 +334,7 @@ public class ModelUtils {
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse("/Textures/Ground/Dirt1.png"); groundMat.set_diffuse("/Textures/Ground/Dirt1.png");
groundMat.set_specular("/Textures/Ground/Dirt1.png"); groundMat.set_specular("/Textures/Ground/Dirt1.png");
m.set_material(groundMat); m.setMaterial(groundMat);
rVal.meshes.add(m); rVal.meshes.add(m);
return rVal; return rVal;
@ -560,7 +560,7 @@ public class ModelUtils {
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse("/Textures/Ground/Dirt1.png"); groundMat.set_diffuse("/Textures/Ground/Dirt1.png");
groundMat.set_specular("/Textures/Ground/Dirt1.png"); groundMat.set_specular("/Textures/Ground/Dirt1.png");
m.set_material(groundMat); m.setMaterial(groundMat);
rVal.meshes.add(m); rVal.meshes.add(m);
return rVal; return rVal;
@ -680,7 +680,7 @@ public class ModelUtils {
Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png");
uiMat.set_diffuse("/Textures/Fonts/myfont1-harsher.png"); uiMat.set_diffuse("/Textures/Fonts/myfont1-harsher.png");
uiMat.set_specular("/Textures/Fonts/myfont1-harsher.png"); uiMat.set_specular("/Textures/Fonts/myfont1-harsher.png");
m.set_material(uiMat); m.setMaterial(uiMat);
rVal.meshes.add(m); rVal.meshes.add(m);

View File

@ -562,4 +562,125 @@ public class RenderUtils {
return particleModel; return particleModel;
} }
public static Model createPlaneModel(){
Model rVal = new Model();
rVal.meshes = new ArrayList();
rVal.modelMatrix = new Matrix4f();
Mesh planeMesh = new Mesh();
planeMesh.mesh = null;
//
// VAO
//
planeMesh.vertexArrayObject = glGenVertexArrays();
glBindVertexArray(planeMesh.vertexArrayObject);
float[] vertexcoords = {
-1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
};
//
//Buffer data to GPU
//
try {
planeMesh.vertexCount = vertexcoords.length / 3;
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(planeMesh.vertexCount * 3);
float[] temp = new float[3];
for (int i = 0; i < planeMesh.vertexCount; i++) {
temp[0] = vertexcoords[i * 3 + 0];
temp[1] = vertexcoords[i * 3 + 1];
temp[2] = vertexcoords[i * 3 + 2];
VertexArrayBufferData.put(temp);
}
VertexArrayBufferData.flip();
planeMesh.buffer_vertices(VertexArrayBufferData, 3);
} catch (NullPointerException ex){
ex.printStackTrace();
}
int[] facedata = {
0,1,2,
1,2,3,
};
//
// FACES
//
planeMesh.faceCount = facedata.length / 3;
planeMesh.elementCount = facedata.length;
IntBuffer elementArrayBufferData = BufferUtils.createIntBuffer(planeMesh.elementCount);
for(int i = 0; i < planeMesh.faceCount; i++){
int[] temp = new int[3];
temp[0] = facedata[i * 3 + 0];
temp[1] = facedata[i * 3 + 1];
temp[2] = facedata[i * 3 + 2];
elementArrayBufferData.put(temp);
}
elementArrayBufferData.flip();
planeMesh.buffer_faces(elementArrayBufferData);
//
// TEXTURE COORDS
//
FloatBuffer texture_coords = BufferUtils.createFloatBuffer(8);
float[] texturedata = {
0,1,
1,1,
0,0,
1,0
};
texture_coords.put(texturedata);
texture_coords.flip();
planeMesh.buffer_texture_coords(texture_coords, 2);
planeMesh.shader = ShaderProgram.loadSpecificShader("Shaders/plane/plane.vs", "Shaders/plane/plane.fs");
planeMesh.hasBones = false;
glBindVertexArray(0);
planeMesh.nodeID = "plane";
planeMesh.parent = rVal;
rVal.meshes.add(planeMesh);
return rVal;
}
} }

View File

@ -168,7 +168,7 @@ public class RenderingEngine {
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/lightDepth/lightDepth.vs", "/Shaders/lightDepth/lightDepth.fs"); lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/lightDepth/lightDepth.vs", "/Shaders/lightDepth/lightDepth.fs");
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.shaderProgram; Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.shaderProgram;
lightDepthBuffer = FramebufferUtils.generateDepthBuffer(); lightDepthBuffer = FramebufferUtils.generateDepthBuffer();
Globals.shadowMapTextureLoc = lightDepthBuffer.getTexture(); Globals.shadowMapTextureLoc = lightDepthBuffer.getTexturePointer();
// glEnable(GL_CULL_FACE); // enabled for shadow mapping // glEnable(GL_CULL_FACE); // enabled for shadow mapping
// //
@ -563,7 +563,7 @@ public class RenderingEngine {
// GL_COLOR_BUFFER_BIT, GL_NEAREST); // GL_COLOR_BUFFER_BIT, GL_NEAREST);
Globals.renderingEngine.setActiveShader(screenTextureShaders); Globals.renderingEngine.setActiveShader(screenTextureShaders);
glBindVertexArray(screenTextureVAO); glBindVertexArray(screenTextureVAO);
glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexture()); glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexturePointer());
// glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexture()); // glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexture());
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0); glBindVertexArray(0);
@ -574,8 +574,8 @@ public class RenderingEngine {
Matrix4f modelTransformMatrix = new Matrix4f(); Matrix4f modelTransformMatrix = new Matrix4f();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
for(Widget currentWidget : Globals.widgetManager.getWidgetList()){ for(Widget currentWidget : Globals.widgetManager.getWidgetList()){
if(currentWidget.isDraw()){ if(currentWidget.getVisible()){
currentWidget.draw(); currentWidget.draw(GL_DEFAULT_FRAMEBUFFER);
} }
} }
@ -614,4 +614,8 @@ public class RenderingEngine {
return activeProgram; return activeProgram;
} }
public void bindFramebuffer(int framebufferPointer){
glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
}
} }

View File

@ -14,23 +14,23 @@ import static org.lwjgl.opengl.GL30.glGenFramebuffers;
*/ */
public class Framebuffer { public class Framebuffer {
int framebuffer; int framebufferPointer;
int texture; int texturePointer;
public Framebuffer(){ public Framebuffer(){
framebuffer = glGenFramebuffers(); framebufferPointer = glGenFramebuffers();
} }
public void setTexture(int texture){ public void setTexturePointer(int texturePointer){
this.texture = texture; this.texturePointer = texturePointer;
} }
public int getTexture(){ public int getTexturePointer(){
return texture; return texturePointer;
} }
public void bind(){ public void bind(){
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
} }
public boolean isComplete(){ public boolean isComplete(){
@ -38,11 +38,11 @@ public class Framebuffer {
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
} }
public int getFramebufferID(){ public int getFramebufferPointer(){
return framebuffer; return framebufferPointer;
} }
public void free(){ public void free(){
glDeleteFramebuffers(framebuffer); glDeleteFramebuffers(framebufferPointer);
} }
} }

View File

@ -58,7 +58,7 @@ public class FramebufferUtils {
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
buffer.setTexture(texture); buffer.setTexturePointer(texture);
//bind texture to fbo //bind texture to fbo
int mipMapLevel = 0; int mipMapLevel = 0;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, mipMapLevel); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, mipMapLevel);
@ -75,6 +75,37 @@ public class FramebufferUtils {
return buffer; return buffer;
} }
public static Framebuffer generateTextureFramebuffer(int width, int height){
Framebuffer buffer = new Framebuffer();
buffer.bind();
//texture
int texture = glGenTextures();
glBindTexture(GL_TEXTURE_2D,texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
buffer.setTexturePointer(texture);
//bind texture to fbo
int mipMapLevel = 0;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, mipMapLevel);
//renderbuffer
int renderBuffer = glGenRenderbuffers();
glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
//bind rbo to fbo
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
//check make sure compiled
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
System.out.println("Framebuffer is not complete!");
}
return buffer;
}
public static Renderbuffer generateScreensizeStencilDepthRenderbuffer(){ public static Renderbuffer generateScreensizeStencilDepthRenderbuffer(){
Renderbuffer buffer = new Renderbuffer(); Renderbuffer buffer = new Renderbuffer();
buffer.bind(); buffer.bind();
@ -101,7 +132,7 @@ public class FramebufferUtils {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
buffer.setTexture(texture); buffer.setTexturePointer(texture);

View File

@ -25,7 +25,7 @@ import static org.lwjgl.opengl.GL30.*;
* @author amaterasu * @author amaterasu
*/ */
public class Texture { public class Texture {
int texture_pointer; int texturePointer;
int width; int width;
int height; int height;
boolean hasTransparency; boolean hasTransparency;
@ -36,9 +36,9 @@ public class Texture {
public Texture(String path){ public Texture(String path){
this.path = path; this.path = path;
//generate the texture object on gpu //generate the texture object on gpu
texture_pointer = glGenTextures(); texturePointer = glGenTextures();
//bind the new texture //bind the new texture
glBindTexture(GL_TEXTURE_2D, texture_pointer); glBindTexture(GL_TEXTURE_2D, texturePointer);
//how are we gonna wrap the texture?? //how are we gonna wrap the texture??
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
@ -126,12 +126,12 @@ public class Texture {
public void bind(){ public void bind(){
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_pointer); glBindTexture(GL_TEXTURE_2D, texturePointer);
} }
public void bind(int attrib_val){ public void bind(int attrib_val){
glActiveTexture(GL_TEXTURE0 + attrib_val); glActiveTexture(GL_TEXTURE0 + attrib_val);
glBindTexture(GL_TEXTURE_2D, texture_pointer); glBindTexture(GL_TEXTURE_2D, texturePointer);
} }
public boolean isTransparent(){ public boolean isTransparent(){
@ -141,4 +141,8 @@ public class Texture {
public String getPath(){ public String getPath(){
return path; return path;
} }
public int getTexturePointer(){
return texturePointer;
}
} }

View File

@ -6,21 +6,13 @@ package electrosphere.renderer.ui;
*/ */
public abstract class Widget { public abstract class Widget {
int width; public int width;
int height; public int height;
int positionX; public int positionX;
int positionY; public int positionY;
boolean draw; public boolean visible = false;
public Widget(int positionX, int positionY, int width, int height, boolean draw) {
this.width = width;
this.height = height;
this.positionX = positionX;
this.positionY = positionY;
this.draw = draw;
}
public int getWidth() { public int getWidth() {
return width; return width;
@ -38,8 +30,8 @@ public abstract class Widget {
return positionY; return positionY;
} }
public boolean isDraw() { public boolean getVisible() {
return draw; return visible;
} }
public void setWidth(int width) { public void setWidth(int width) {
@ -58,10 +50,10 @@ public abstract class Widget {
this.positionY = positionY; this.positionY = positionY;
} }
public void setDraw(boolean draw) { public void setVisible(boolean draw) {
this.draw = draw; this.visible = draw;
} }
public abstract void draw(); public abstract void draw(int parentFramebufferPointer);
} }

View File

@ -2,6 +2,8 @@ package electrosphere.renderer.ui;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.renderer.ui.font.TextBox; import electrosphere.renderer.ui.font.TextBox;
import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable;
import electrosphere.renderer.ui.widgets.ImagePanel;
/** /**
* *
@ -45,4 +47,42 @@ public class WidgetUtils {
return rVal; return rVal;
} }
public static LayoutSchemeListScrollable createListTEST(){
LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(200, 200, 500, 500, true);
rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
rVal.addWidget(WidgetUtils.createTextBox(100, 100, 500, 500, 3, 10, "TEST", true));
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static Widget createWindowTEST(){
Window rVal = new Window(500, 500, 500, 500);
//panel 1
ImagePanel imagePanel = new ImagePanel();
imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
imagePanel.setPositionX(100);
imagePanel.setPositionY(100);
imagePanel.setVisible(true);
rVal.addWidget(imagePanel);
//panel 2
imagePanel = new ImagePanel();
imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
imagePanel.setVisible(true);
rVal.addWidget(imagePanel);
rVal.setVisible(true);
//window top
imagePanel = new ImagePanel();
imagePanel.setTexture(Globals.assetManager.fetchTexture("Textures/ui/WindowBorder.png"));
imagePanel.setWidth(100);
imagePanel.setHeight(50);
imagePanel.setPositionX(200);
imagePanel.setPositionY(50);
imagePanel.setVisible(true);
rVal.addWidget(imagePanel);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
} }

View File

@ -0,0 +1,93 @@
package electrosphere.renderer.ui;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3f;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL30.*;
/**
*
* @author amaterasu
*/
public class Window extends Widget {
List<Widget> widgetList = new LinkedList();
Framebuffer widgetBuffer;
Material customMat = new Material();
Vector3f boxPosition = new Vector3f();
Vector3f boxDimensions = new Vector3f();
Vector3f texPosition = new Vector3f(0,0,0);
Vector3f texScale = new Vector3f(1,1,0);
public Window(int positionX, int positionY, int width, int height){
//TODO: figure out why this has to be 1920x1080
// widgetBuffer = FramebufferUtils.generateTextureFramebuffer(width, height);
widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
customMat.setTexturePointer(widgetBuffer.getTexturePointer());
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
}
@Override
public void draw(int parentFramebufferPointer) {
widgetBuffer.bind();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Widget child : widgetList){
child.draw(widgetBuffer.getFramebufferPointer());
}
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
}
public void pack() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void addWidget(Widget widget) {
widgetList.add(widget);
widget.setVisible(false);
}
public List<Widget> getWidgets() {
return widgetList;
}
public void destroy() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void setTextureCoord(int x, int y){
float ndcX = (float)x/Globals.WINDOW_WIDTH;
float ndcY = (float)y/Globals.WINDOW_HEIGHT;
texPosition = new Vector3f(ndcX,ndcY,0);
}
public void setTextureScale(int x, int y){
float ndcWidth = (float)x/Globals.WINDOW_WIDTH;
float ndcHeight = (float)y/Globals.WINDOW_HEIGHT;
texScale = new Vector3f(ndcWidth,ndcHeight,0);
}
}

View File

@ -25,7 +25,6 @@ public class TextBox extends Widget{
Vector3f color = new Vector3f(0,0,0); Vector3f color = new Vector3f(0,0,0);
public TextBox(int positionX, int positionY, int width, int height, int rows, int cols, String text, boolean render, boolean editable) { public TextBox(int positionX, int positionY, int width, int height, int rows, int cols, String text, boolean render, boolean editable) {
super(positionX,positionY,width,height,render);
this.positionX = positionX; this.positionX = positionX;
this.positionY = positionY; this.positionY = positionY;
this.width = width; this.width = width;
@ -73,7 +72,8 @@ public class TextBox extends Widget{
@Override @Override
public void draw(){ public void draw(int parentFramebufferPointer){
Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer);
float ndcX = (float)positionX/Globals.WINDOW_WIDTH; float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT; float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
float ndcWidth = (float)width/Globals.WINDOW_WIDTH; float ndcWidth = (float)width/Globals.WINDOW_WIDTH;

View File

@ -1,46 +0,0 @@
package electrosphere.renderer.ui.layout;
import electrosphere.renderer.ui.Widget;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author amaterasu
*/
public class LayoutSchemeList extends Widget implements LayoutScheme {
List<Widget> widgetList = new LinkedList();
public LayoutSchemeList(int positionX, int positionY, int width, int height, boolean draw){
super(positionX,positionY,width,height,draw);
}
@Override
public void draw() {
for(Widget child : widgetList){
child.draw();
}
}
@Override
public void addWidget(Widget widget) {
widgetList.add(widget);
widget.setDraw(false);
}
@Override
public List<Widget> getWidgets() {
return widgetList;
}
@Override
public void destroy() {
}
@Override
public void pack() {
}
}

View File

@ -1,54 +1,96 @@
package electrosphere.renderer.ui.layout; package electrosphere.renderer.ui.layout;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
import electrosphere.renderer.framebuffer.Framebuffer; import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.ui.Widget; import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.Model;
import electrosphere.renderer.assetmanager.AssetDataStrings;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.joml.Vector3f;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT; import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT; import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor; import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
import static org.lwjgl.opengl.GL13.GL_TEXTURE1;
import static org.lwjgl.opengl.GL13.GL_TEXTURE2;
import static org.lwjgl.opengl.GL13.GL_TEXTURE3;
import static org.lwjgl.opengl.GL13.glActiveTexture;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
/** /**
* *
* @author amaterasu * @author amaterasu
*/ */
public class LayoutSchemeListScrollable extends Widget implements LayoutScheme { public class LayoutSchemeListScrollable extends Widget {
List<Widget> widgetList = new LinkedList(); List<Widget> widgetList = new LinkedList();
Framebuffer widgetBuffer = new Framebuffer(); Framebuffer widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
Material customMat = new Material();
Vector3f boxPosition = new Vector3f();
Vector3f boxDimensions = new Vector3f();
Vector3f texPosition = new Vector3f(0,0,0);
Vector3f texScale = new Vector3f(1,1,0);
public LayoutSchemeListScrollable(int positionX, int positionY, int width, int height, boolean draw){ public LayoutSchemeListScrollable(int positionX, int positionY, int width, int height, boolean draw){
super(positionX,positionY,width,height,draw); customMat.setTexturePointer(widgetBuffer.getTexturePointer());
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Branch.png").getTexturePointer());
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
} }
static float aaaa = 0;
@Override @Override
public void draw() { public void draw(int parentFramebufferPointer) {
widgetBuffer.bind(); widgetBuffer.bind();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Widget child : widgetList){ for(Widget child : widgetList){
child.draw(); child.draw(widgetBuffer.getFramebufferPointer());
} }
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
glBindFramebuffer(GL_FRAMEBUFFER, 0);
aaaa = aaaa + 0.0005f;
if(aaaa > 1){
aaaa = -1;
}
texPosition.y = aaaa;
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
} }
@Override
public void pack() { public void pack() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }
@Override
public void addWidget(Widget widget) { public void addWidget(Widget widget) {
widgetList.add(widget); widgetList.add(widget);
widget.setDraw(false); widget.setVisible(false);
} }
@Override
public List<Widget> getWidgets() { public List<Widget> getWidgets() {
return widgetList; return widgetList;
} }
@Override
public void destroy() { public void destroy() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }

View File

@ -7,7 +7,7 @@ import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.FontUtils; import electrosphere.renderer.ui.font.FontUtils;
import org.joml.Vector3f; import org.joml.Vector3f;
public class TextBox extends Widget{ public class TextBox extends Widget{
int positionX; int positionX;
@ -20,7 +20,6 @@ public class TextBox extends Widget{
Vector3f scalar; Vector3f scalar;
public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable) { public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable) {
super(positionX,positionY,width,height,render);
this.positionX = positionX; this.positionX = positionX;
this.positionY = positionY; this.positionY = positionY;
this.width = width; this.width = width;
@ -30,7 +29,6 @@ public class TextBox extends Widget{
} }
public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable, Vector3f scalar) { public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable, Vector3f scalar) {
super(positionX,positionY,width,height,render);
this.positionX = positionX; this.positionX = positionX;
this.positionY = positionY; this.positionY = positionY;
this.width = width; this.width = width;
@ -57,7 +55,7 @@ public class TextBox extends Widget{
@Override @Override
public void draw(){ public void draw(int parentFramebufferPointer){
throw new UnsupportedOperationException("Transparent Text box draw function not implemented yet oop"); throw new UnsupportedOperationException("Transparent Text box draw function not implemented yet oop");
// float ndcX = (float)positionX/Globals.WINDOW_WIDTH; // float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
// float ndcY = (float)positionY/Globals.WINDOW_HEIGHT; // float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;

View File

@ -0,0 +1,90 @@
package electrosphere.renderer.ui.widgets;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.ui.Widget;
import org.joml.Vector3f;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
/**
*
* @author amaterasu
*/
public class ImagePanel extends Widget {
Material customMat = new Material();
Texture texture = null;
Vector3f boxPosition = new Vector3f(0,0,0);
Vector3f boxDimensions = new Vector3f(1,1,0);
Vector3f texPosition = new Vector3f(0,0,0);
Vector3f texScale = new Vector3f(1,1,0);
public ImagePanel(){
texture = Globals.assetManager.fetchTexture("Textures/default_diffuse.png");
customMat.setTexturePointer(texture.getTexturePointer());
}
public void setTexture(Texture texture){
customMat.setTexturePointer(texture.getTexturePointer());
}
public Texture getTexture(){
return texture;
}
@Override
public void setPositionY(int positionY) {
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
boxPosition.y = ndcY;
super.setPositionY(positionY);
}
@Override
public void setPositionX(int positionX) {
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
boxPosition.x = ndcX;
super.setPositionX(positionX);
}
@Override
public void setHeight(int height) {
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
boxDimensions.y = ndcHeight;
super.setHeight(height);
}
@Override
public void setWidth(int width) {
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
boxDimensions.x = ndcWidth;
super.setWidth(width);
}
@Override
public void draw(int parentFramebufferPointer) {
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
}
}

View File

@ -88,7 +88,7 @@ public class ModelLoader {
} }
//once we've either added default textures or actual textures, //once we've either added default textures or actual textures,
//set the current mesh's material to this new one //set the current mesh's material to this new one
current_mesh.set_material(final_material); current_mesh.setMaterial(final_material);
} else { } else {
LoggerInterface.loggerRenderer.WARNING("Failed to load texture for node " + current_mesh.nodeID + " of model " + path); LoggerInterface.loggerRenderer.WARNING("Failed to load texture for node " + current_mesh.nodeID + " of model " + path);
} }