Results 1 to 3 of 3
  1. #1
    migi0027 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default LWJGL problem with custom format...

    Hello,

    Im a new programmer for this LWJGL, and i recently wanted to create my own file format for vertixes, and... Its not working.

    So i would like to ask why..

    Code:

    Java Code:
    package miguel.petersen.main;
    
    import java.awt.Font;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    
    import org.lwjgl.LWJGLException;
    import org.lwjgl.examples.spaceinvaders.Texture;
    import org.lwjgl.input.Keyboard;
    import org.lwjgl.opengl.Display;
    import org.lwjgl.opengl.DisplayMode;
    import org.lwjgl.opengl.GL11;
    
    import org.newdawn.slick.Color;
    import org.newdawn.slick.TrueTypeFont;
    import org.newdawn.slick.opengl.TextureLoader;
    import org.newdawn.slick.util.ResourceLoader;
     
    public class main{
    
    	/** The fonts to draw to the screen */
    	private TrueTypeFont font;
    	private TrueTypeFont font2;
    	
    	/** Boolean flag on whether AntiAliasing is enabled or not */
    	private boolean antiAlias = true;
    	
    	boolean KeyF = false;
    	
    	int angle;
    	
    	public org.newdawn.slick.opengl.Texture mclogo;
    	
    	/**
    	 * Start the test 
    	 */
    	public void start() {
    		initGL(800,600);
    		init();
     
    		while (true) {
    			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    			CheckKeyboard();
    			
    			render();
     
    			Display.update();
    			Display.sync(100);
     
    			if (Display.isCloseRequested()) {
    				Display.destroy();
    				System.exit(0);
    			}
    		}
    	}
     
    	/**
    	 * Initialize the GL display
    	 * 
    	 * @param width The width of the display
    	 * @param height The height of the display
    	 */
    	private void initGL(int width, int height) {
    		try {
    			Display.setDisplayMode(new DisplayMode(width,height));
    			Display.create();
    			Display.setVSyncEnabled(true);
    		} catch (LWJGLException e) {
    			e.printStackTrace();
    			System.exit(0);
    		}
     
    		GL11.glEnable(GL11.GL_TEXTURE_2D);               
            
    		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);          
            
            	// enable alpha blending
            	GL11.glEnable(GL11.GL_BLEND);
            	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            
            	GL11.glViewport(0,0,width,height);
    		GL11.glMatrixMode(GL11.GL_MODELVIEW);
    
    		GL11.glMatrixMode(GL11.GL_PROJECTION);
    		GL11.glLoadIdentity();
    		GL11.glOrtho(0, width, height, 0, 1, -1);
    		GL11.glMatrixMode(GL11.GL_MODELVIEW);
    	}
     
    	/**
    	 * Initialize resources
    	 */
    	
    	public void LoadTextures()
    	{
    		try {
    			mclogo = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("MCLogo.PNG"));
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    	
    	public void init() {
    		// load a default java font
    		Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
    		font = new TrueTypeFont(awtFont, antiAlias);
    		
    		LoadTextures();
    		
    		// load font from file
    		try {
    			InputStream inputStream	= ResourceLoader.getResourceAsStream("unispace.ttf");
    			
    			Font awtFont2 = Font.createFont(Font.TRUETYPE_FONT, inputStream);
    			awtFont2 = awtFont2.deriveFont(24f); // set font size
    			font2 = new TrueTypeFont(awtFont2, antiAlias);
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
     
    	/**
    	 * Game loop render
    	 */
    	
    	public void CheckKeyboard()
    	{
    		if (Keyboard.isKeyDown(Keyboard.KEY_F))
    		{
    			KeyF = true;
    		}
    		else
    		{
    			KeyF = false;
    		}
    	}
    	
    	public void render() {
    		Color.white.bind();
    		
    		try {
    			loadlvo("Cube.lvo");
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		//if (KeyF == true){IngameLog("F has been pressed!");}else{IngameLog("F has not been presssed...");}
    		
    		renderlogo();
    	}
    	
    	public void loadlvo(String file) throws IOException
    	{
    		try {
    			BufferedReader stream = new BufferedReader(new FileReader(file));
    			
    			String line;
    			
    			GL11.glBegin(GL11.GL_QUADS);
    			while((line = stream.readLine()) != null)
    			{
    				if (line.startsWith("v:"))
    				{
    					float x = Float.valueOf(line.split(",")[1]);
    					float y = Float.valueOf(line.split(",")[1]);
    					float z = Float.valueOf(line.split(",")[1]);
    					
    					IngameLog("X:" + x + " Y:" + y + " Z:" + z);
    					
    					GL11.glColor3f(1, 0, 0);
    					GL11.glVertex3f(x, y, z);
    				}
    			}
    			GL11.glEnd();
    			
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    	
    	public void renderlogo()
    	{
    		mclogo.bind();
    		
    		GL11.glBegin(GL11.GL_QUADS);
    		
    		GL11.glTexCoord2f(0, 0);
    		GL11.glVertex2f(10, 10);
    	
    		GL11.glTexCoord2f(1, 0);
    		GL11.glVertex2f(10+mclogo.getTextureWidth(), 10);
    		
    		GL11.glTexCoord2f(1, 1);
    		GL11.glVertex2f(10+mclogo.getTextureWidth(), 10+mclogo.getTextureHeight());
    		
    		GL11.glTexCoord2f(0, 1);
    		GL11.glVertex2f(10, 10+mclogo.getTextureHeight());
    		
    		GL11.glEnd();
    	}
    
    	public void IngameLog(String message)
    	{
    		font.drawString(20, Display.getHeight() - 50, "Log: " + message, Color.white);
    	}
     
    	/**
    	 * Main method
    	 */
    	public static void main(String[] argv) {
    		main fontExample = new main();
    		fontExample.start();
    	}
    }
    The most important for you in here is loadlvo and render and initGL

    My actual format file:
    Java Code:
    v:1.0,1.0,-1.0
    v:-1.0,1.0,-1.0
    v:-1.0,1.0,1.0
    v:1.0,1.0,1.0
    v:1.0,-1.0,1.0
    v:-1.0,-1.0,1.0
    v:-1.0,-1.0,-1.0
    v:1.0,-1.0,-1.0
    v:1.0,1.0,1.0
    v:-1.0,1.0,1.0
    v:-1.0,-1.0,1.0
    v:1.0,-1.0,1.0
    v:1.0,-1.0,-1.0
    v:-1.0,-1.0,-1.0
    v:-1.0,1.0,-1.0
    v:1.0,1.0,-1.0
    v:-1.0,1.0,1.0
    v:-1.0,1.0,-1.0
    v:-1.0,-1.0,-1.0
    v:-1.0,-1.0,1.0
    v:1.0,1.0,-1.0
    v:1.0,1.0,1.0
    v:1.0,-1.0,1.0
    v:1.0,-1.0,-1.0
    But nothing seems to come, but only that my screen turns(loaded images in LWJGL) abit red...

    Please help me, i'm unpacient...

  2. #2
    migi0027 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: LWJGL problem with custom format...

    Please! Im unpacient...

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: LWJGL problem with custom format...

    Quote Originally Posted by migi0027 View Post
    Please! Im unpacient...
    Read this: How To Ask Questions The Smart Way

    You've dumped a bunch of code here, without bothering to use the standard naming conventions or even be very specific about what the actual problem is. You've shown no evidence that you've tried to narrow your problem down to an SSCCE or do any debugging on your own. Yet you complain when we don't do your work fast enough for you?

    Show some effort, and we'll go from there.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 0
    Last Post: 05-21-2012, 10:31 AM
  2. LWJGL help please
    By Brandon@JavaForums in forum Advanced Java
    Replies: 12
    Last Post: 12-31-2011, 10:19 AM
  3. lwjgl help PLEASE!
    By Brandon in forum New To Java
    Replies: 1
    Last Post: 10-06-2011, 06:11 AM
  4. customize formatter class to take in custom format?
    By diskhub in forum Advanced Java
    Replies: 1
    Last Post: 05-17-2010, 06:50 PM
  5. Custom Format a Textbox in PDF Forms
    By keelyn in forum New To Java
    Replies: 0
    Last Post: 08-11-2009, 07:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •