Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- import static org.lwjgl.opengl.GL11.*;
- import java.awt.Font;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import org.lwjgl.input.Mouse;
- import org.lwjgl.opengl.GL11;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.TrueTypeFont;
- import org.newdawn.slick.opengl.Texture;
- import org.newdawn.slick.opengl.TextureLoader;
- public class Renderer
- {
- public Art art;
- private Metamorph mm;
- public static final String MAINFONT = "Smudger LET";
- public Renderer(Art a)
- {
- art = a;
- }
- public void render()
- {
- mm = Metamorph.instance;
- if(Metamorph.instance.currentScreen == EnumScreens.MAIN)
- {
- renderMainMenuWithGL();
- }
- if(Metamorph.instance.currentScreen == EnumScreens.GAME)
- {
- renderRunningGameWithGL();
- }
- //System.out.printf("Rendering ");
- }
- private void renderMainMenuWithGL()
- {
- //System.out.println("Main Menu!");
- glColor4f(1, 1, 1, 1);
- try
- {
- Texture bg = loadTexture("mockery");
- bg.bind();
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- //drawQuad(0, 0, 1280, 720, 0, 0, 1280, 720);
- glPushMatrix();
- {
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);glVertex2f(0, 0);
- glTexCoord2f(0, 1);glVertex2f(0, 720);
- glTexCoord2f(1, 1);glVertex2f(1280, 720);
- glTexCoord2f(1, 0);glVertex2f(1280, 0);
- glEnd();
- }
- glPopMatrix();
- TrueTypeFont f = loadFont(MAINFONT, Font.PLAIN, 50);
- TrueTypeFont fb = loadFont(MAINFONT, Font.PLAIN, 48);
- int sel = -1;
- if(Mouse.getX() > 1000 && Mouse.getX() < 1240 && Mouse.getY() > 282.5F && Mouse.getY()< 737.5F)
- sel = Math.round((Mouse.getY() - 337.5F)/75F);
- if(sel == 0)
- drawStringRight(fb, 1240, 350, "Story", new Color(0xff516b6b));
- else
- drawStringRight(f, 1240, 350, "Story", new Color(0xff516b6b));
- }
- private void renderRunningGameWithGL()
- {
- }
- private void drawQuad(float drawX, float drawY, float drawX2, float drawY2,
- float srcX, float srcY, float srcX2, float srcY2) {
- float DrawWidth = drawX2 - drawX;
- float DrawHeight = drawY2 - drawY;
- float TextureSrcX = srcX / 1280;
- float TextureSrcY = srcY / 720;
- float SrcWidth = srcX2 - srcX;
- float SrcHeight = srcY2 - srcY;
- float RenderWidth = (SrcWidth / 1280);
- float RenderHeight = (SrcHeight / 720);
- GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
- GL11.glVertex2f(drawX, drawY);
- GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight);
- GL11.glVertex2f(drawX, drawY + DrawHeight);
- GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
- GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight);
- GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY);
- GL11.glVertex2f(drawX + DrawWidth, drawY);
- }
- public static Texture loadTexture(String key)
- {
- try
- {
- return TextureLoader.getTexture("png", new FileInputStream(new File("res/images/" + key + ".png")));
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
- private void drawStringCentered(TrueTypeFont f, int x, int y, String s, Color c)
- {
- glPushMatrix();
- f.drawString(x-f.getWidth(s)/2, y, s, c);
- glPopMatrix();
- }
- private void drawStringRight(TrueTypeFont f, int x, int y, String s, Color c)
- {
- glPushMatrix();
- f.drawString(x-f.getWidth(s), y, s, c);
- glPopMatrix();
- }
- private TrueTypeFont loadFont(String name, int style, int size)
- {
- Font f = new Font(name, style, size);
- return new TrueTypeFont(f, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement