Created
November 11, 2024 16:17
-
-
Save BliepMonster/bacfea87be387adbbbb54a7db3744245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Engine.Display; | |
import org.lwjgl.opengl.GL11; | |
import java.awt.*; | |
public class draw { | |
public static void square(DisplayScreen screen, Color color, float x1, float y1, float height) { | |
GL11.glDisable(GL11.GL_TEXTURE_2D); | |
GL11.glColor4f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f, 1); | |
GL11.glBegin(GL11.GL_QUADS); | |
int screenWidth = screen.getWidth(); | |
int screenHeight = screen.getHeight(); | |
float extendedX = (x1 * screenHeight) / screenWidth + (height * screenHeight) / screenWidth; | |
// Define the vertices of the square | |
GL11.glVertex2f(extendedX, y1); | |
GL11.glVertex2f((x1 * screenHeight) / screenWidth, y1); | |
GL11.glVertex2f((x1 * screenHeight) / screenWidth, y1 + height); | |
GL11.glVertex2f(extendedX, y1 + height); | |
GL11.glEnd(); | |
GL11.glEnable(GL11.GL_TEXTURE_2D); | |
} | |
public static void rect(DisplayScreen screen, Color color, float x1, float y1, float width, float height) { | |
int screenHeight = screen.getHeight(); | |
int screenWidth = screen.getWidth(); | |
GL11.glDisable(GL11.GL_TEXTURE_2D); | |
GL11.glBegin(GL11.GL_QUADS); | |
GL11.glColor4f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f, 1); | |
GL11.glVertex2f(x1 + (width*screenHeight)/screenWidth, y1); | |
GL11.glVertex2f(x1, y1); | |
GL11.glVertex2f(x1, y1 + height); | |
GL11.glVertex2f(x1 + (width*screenHeight)/screenWidth, y1 + height); | |
GL11.glEnd(); | |
GL11.glEnable(GL11.GL_TEXTURE_2D); | |
} | |
public static void image(DisplayScreen screen, Texture texture, float x1, float y1, float size) { | |
// Reset color to white to ensure the texture is displayed without tint | |
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
texture.bind(); | |
GL11.glBegin(GL11.GL_QUADS); | |
int screenWidth = screen.getWidth(); | |
int screenHeight = screen.getHeight(); | |
float extendedX = (x1 * screenHeight) / screenWidth + (size * screenHeight) / screenWidth; | |
GL11.glTexCoord2f(1, 0); | |
GL11.glVertex2f(extendedX, y1); | |
GL11.glTexCoord2f(0, 0); | |
GL11.glVertex2f((x1 * screenHeight) / screenWidth, y1); | |
GL11.glTexCoord2f(0, 1); | |
GL11.glVertex2f((x1 * screenHeight) / screenWidth, y1 + size); | |
GL11.glTexCoord2f(1, 1); | |
GL11.glVertex2f(extendedX, y1 + size); | |
GL11.glEnd(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment