use of io.xol.chunkstories.renderer.OpenGLRenderingContext in project chunkstories by Hugobros3.
the class FakeImmediateModeDebugRenderer method glEnd.
public static void glEnd() {
OpenGLRenderingContext renderingContext = Client.getInstance().getGameWindow().getRenderingInterface();
renderingContext.setCullingMode(CullingMode.DISABLED);
renderingContext.setBlendMode(BlendMode.MIX);
renderingContext.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
// ShadersLibrary.getShaderProgram("overlay");
Shader overlayProgram = renderingContext.useShader("overlay");
camera.setupShader(overlayProgram);
overlayProgram.setUniform4f("colorIn", color);
data.flip();
vertexBuffer.uploadData(data);
renderingContext.bindAttribute("vertexIn", vertexBuffer.asAttributeSource(VertexFormat.FLOAT, 3));
// renderingContext.bindAttribute("vertexIn", new FloatBufferAttributeSource(data, 3));
renderingContext.draw(mode == GL_TRIANGLES ? Primitive.TRIANGLE : Primitive.LINE, 0, size);
renderingContext.setBlendMode(BlendMode.DISABLED);
data.clear();
size = 0;
}
use of io.xol.chunkstories.renderer.OpenGLRenderingContext in project chunkstories by Hugobros3.
the class CorneredBoxDrawer method drawCorneredBoxTiled_.
public static void drawCorneredBoxTiled_(float posx, float posy, float width, float height, int cornerSize, Texture2D texture, int textureSize, int scale) {
OpenGLRenderingContext renderingContext = Client.getInstance().getGameWindow().getRenderingInterface();
GuiRenderer guiRenderer = renderingContext.getGuiRenderer();
float topLeftCornerX = posx - width / 2;
float topLeftCornerY = posy - height / 2;
float botRightCornerX = posx + width / 2;
float botRightCornerY = posy + height / 2;
// Debug helper
// guiRenderer.drawBoxWindowsSpace(topLeftCornerX, topLeftCornerY, botRightCornerX, botRightCornerY, 0, 0, 0, 0, null, true, false, new Vector4f(1.0, 1.0, 0.0, 1.0));
int cornerSizeScaled = scale * cornerSize;
float textureSizeInternal = textureSize - cornerSize * 2;
float insideWidth = width - cornerSizeScaled * 2;
float insideHeight = height - cornerSizeScaled * 2;
float texCoordInsideTopLeft = ((float) cornerSize) / textureSize;
float texCoordInsideBottomRight = ((float) (textureSize - cornerSize)) / textureSize;
// Fill the inside of the box
for (int fillerX = 0; fillerX < insideWidth; fillerX += textureSizeInternal * scale) {
for (int fillerY = 0; fillerY < insideHeight; fillerY += textureSizeInternal * scale) {
float toFillX = Math.min(textureSizeInternal * scale, insideWidth - fillerX);
float toFillY = Math.min(textureSizeInternal * scale, insideHeight - fillerY);
float startX = topLeftCornerX + cornerSizeScaled + fillerX;
float startY = topLeftCornerY + cornerSizeScaled + fillerY;
guiRenderer.drawBoxWindowsSpace(startX, startY, startX + toFillX, startY + toFillY, texCoordInsideTopLeft, texCoordInsideTopLeft + toFillY / textureSize / scale, texCoordInsideTopLeft + toFillX / textureSize / scale, texCoordInsideTopLeft, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
}
// Fill the horizontal sides
for (int fillerX = 0; fillerX < insideWidth; fillerX += textureSizeInternal * scale) {
float toFillX = Math.min(textureSizeInternal * scale, insideWidth - fillerX);
float startX = topLeftCornerX + cornerSizeScaled + fillerX;
float startY = topLeftCornerY;
guiRenderer.drawBoxWindowsSpace(startX, startY + height - cornerSizeScaled, startX + toFillX, startY + height, texCoordInsideTopLeft, texCoordInsideTopLeft, texCoordInsideTopLeft + toFillX / textureSize / scale, 0, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
guiRenderer.drawBoxWindowsSpace(startX, startY, startX + toFillX, startY + cornerSizeScaled, texCoordInsideTopLeft, 1.0f, texCoordInsideTopLeft + toFillX / textureSize / scale, texCoordInsideBottomRight, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
// Fill the vertical sides
for (int fillerY = 0; fillerY < insideHeight; fillerY += textureSizeInternal * scale) {
float toFillY = Math.min(textureSizeInternal * scale, insideHeight - fillerY);
float startY = topLeftCornerY + cornerSizeScaled + fillerY;
float startX = topLeftCornerX;
guiRenderer.drawBoxWindowsSpace(startX, startY, startX + cornerSizeScaled, startY + toFillY, 0, texCoordInsideBottomRight - (textureSizeInternal * scale - toFillY) / textureSize / scale, texCoordInsideTopLeft, texCoordInsideTopLeft, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
guiRenderer.drawBoxWindowsSpace(startX + width - cornerSizeScaled, startY, startX + width, startY + toFillY, texCoordInsideBottomRight, texCoordInsideBottomRight - (textureSizeInternal * scale - toFillY) / textureSize / scale, 1.0f, texCoordInsideTopLeft, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
// Fill the 4 corners
guiRenderer.drawBoxWindowsSpace(topLeftCornerX, botRightCornerY - cornerSizeScaled, topLeftCornerX + cornerSizeScaled, botRightCornerY, 0, texCoordInsideTopLeft, texCoordInsideTopLeft, 0, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
guiRenderer.drawBoxWindowsSpace(topLeftCornerX, topLeftCornerY, topLeftCornerX + cornerSizeScaled, topLeftCornerY + cornerSizeScaled, 0, 1.0f, texCoordInsideTopLeft, texCoordInsideBottomRight, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
guiRenderer.drawBoxWindowsSpace(botRightCornerX - cornerSizeScaled, botRightCornerY - cornerSizeScaled, botRightCornerX, botRightCornerY, texCoordInsideBottomRight, texCoordInsideTopLeft, 1.0f, 0, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
guiRenderer.drawBoxWindowsSpace(botRightCornerX - cornerSizeScaled, topLeftCornerY, botRightCornerX, topLeftCornerY + cornerSizeScaled, texCoordInsideBottomRight, 1.0f, 1.0f, texCoordInsideBottomRight, texture, true, false, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
use of io.xol.chunkstories.renderer.OpenGLRenderingContext in project chunkstories by Hugobros3.
the class GLFWGameWindow method createOpenGLContext.
private void createOpenGLContext() {
logger().info("Creating an OpenGL Windows [title:" + windowName + ", width:" + windowWidth + ", height:" + windowHeight + "]");
try {
computeDisplayModes();
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
// We want anything above 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if (ClientLimitations.debugOpenGL)
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
glfwWindowHandle = glfwCreateWindow(windowWidth, windowHeight, windowName, 0, 0);
if (glfwWindowHandle == NULL)
throw new RuntimeException("Failed to create window");
glfwMakeContextCurrent(glfwWindowHandle);
capabilities = GL.createCapabilities();
systemInfo();
glInfo();
switchResolution();
glfwSwapInterval(0);
glfwShowWindow(glfwWindowHandle);
// Enable error callback
if (ClientLimitations.debugOpenGL)
glDebugMessageCallbackARB(new OpenGLDebugOutputCallback(Thread.currentThread()), 0);
// Oops.. Didn't use any VAOs anywhere so we put this there to be GL 3.2 core compliant
int vao = glGenVertexArrays();
glBindVertexArray(vao);
// displaySplashScreen();
renderingContext = new OpenGLRenderingContext(this);
} catch (Exception e) {
logger().info("A fatal error occured ! If you see the dev, show him this message !", e);
// e.printStackTrace();
// e.printStackTrace(logger().getPrintWriter());
}
}
Aggregations