Show Posts
|
|
Pages: [1]
|
|
2
|
Java Game APIs & Engines / OpenGL Development / LWJGL Object Coordinates
|
on: 2012-04-24 05:09:02
|
|
I'm trying to get the object coordinates of objects I'm drawing in 3D space. I've read that the GL_MODELVIEW_MATRIX is the comprised of the GL_PROJECTION_MATRIX and the transformation_matrix(which isn't defined for lwjgl).
So, are the object coordinates simply in the matrix: transformation_matrix = GL_PROJECTION_MATRIX * inverse(GL_MODELVIEW_MATRIX);
Also... If I'm letting the user move the camera around freely in the 3D space, do I have to add anything to the computation when I'm solving for the transformation_matrix?
I've already read that this ISN'T the way it should be done, and that I should be keeping track of any x,y and z coordinates myself. (As this isn't what OpenGL was meant for) In that case, what method would I use to keep track of x,y and z coordinates if I'm consistently doing something similar to:
glTranslatef(x, y, z); glRotatef(degree, 0, 1, 0); //Where there could, or could NOT be a rotation glRotatef(degree, 1, 0, 0);//Where there could, or could NOT be a rotation glTranslatef(x, y, z); ... etc.
|
|
|
|
|
4
|
Java Game APIs & Engines / OpenGL Development / Re: TWL or Slick2D Development
|
on: 2012-04-23 03:41:10
|
|
That's what I originally said.
I have everything drawn. I just need a library to throw some 2D buttons on top of what I have. (I'm assuming it's possible w/o having to create my own buttons, but I could be wrong.)
That is the reason I am wanting to use TWL or SLick2D. Just for the buttons/text.
The hard part for me is figuring out how put the buttons/text on the UI.
|
|
|
|
|
5
|
Java Game APIs & Engines / OpenGL Development / Re: TWL or Slick2D Development
|
on: 2012-04-23 03:12:09
|
Slick2D was designed to hide the low-level GL calls from the user, so generally speaking you should be using Slick's utilities instead of calling GL11/Display directly. If you just need text, buttons and a text field, then use Slick2D's Font/UI classes, as they will suffice. If you want a more professional interface, with tables, combo boxes, text areas, etc. use TWL. It has a much steeper learning curve, requires you to design your own themes (although you could use an existing theme), and takes a little bit of work setting up with Slick2D. Hmm... The points I'm drawing are in 3D space though. I can't seem to find anything with the Slick API that allows me to draw anything in depth. How would I mimick something similar to : glVertex3f( ... ) in slick2D?
|
|
|
|
|
7
|
Java Game APIs & Engines / OpenGL Development / TWL or Slick2D Development
|
on: 2012-04-23 02:17:35
|
I've developed a small program that parses a Biovision Hierarchy file (.bvh) and I currently have a very basic canvas that displays the animation. See attachment for canvas example. I'm not sure if this is old-fashioned or not, but I've got everything rendered to org.lwjgl.opengl.Display I'm also using the org.lwjgl.opengl.GL11.* methods. Now, I've come across a problem. I want my UI to have a few buttons and some text around the UI displaying information like filename, etc. What I need help with is choosing a library for such a thing. I can't see how to just "lay" TWL or Slick2D objects on top of the code I have to add a few buttons and some text. So it brings me to ask, should I be using TWL or Slick2D or neither? Or, if I am to use either of these 2 libraries, will I have to extend Widgets (for TWL) or extend BasicGame( SLick2D) and THEN integrate what I have into either of these libraries? I'm also on a short timeframe so another question I will ask is: Which of these libraries is quicker to learn/pickup and get my hands dirty? 
|
|
|
|
|
8
|
Java Game APIs & Engines / OpenGL Development / Bitmap & Font Help
|
on: 2011-12-26 20:48:28
|
I'm reading the red book and I'm in the section about bitmaps and fonts. What I'm trying to do is setup a bitmap for each letter (uppercase/lowercase) and number and store the data into an inner-class I call RasterFontInfo. The class RasterFont contains RasterFontInfo and sets up the Map. A bitmap for each char can be called from a Map that is setup like: Map<Character, RasterFontInfo> map; RasterFontInfo contains width, height, x0, y0, and a ByteBuffer which holds the bitmap data. So far, I've been pretty successful but I'm now blocked with the following problem:  Uploaded with ImageShack.usAll of the letters are showing up correctly except for m, G, J, M, O, Q, and 1. I've tried looking for patterns between these but I can't see any. I'm hoping someone can give insight as to why the letters show up like this. If you need the code I have the following: The code I'm using to draw each letter looks like: 1 2 3 4 5 6 7 8
| glTranslatef(0.0f, 0.0f, zTranslation); glRasterPos2f(-3.2f, 0f); char[] phrase = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); for(char c : phrase) { RasterFontInfo rfi = characterMap.get(c); glBitmap(rfi.getWidth(), rfi.getHeight(), (float)rfi.getX0(), (float)rfi.getY0(), (float)rfi.getWidth()+2, 0, rfi.getBuffer()); } |
Code for deriving a RasterFontInfo object: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| private RasterFontInfo deriveRasterFontInfo(char c) { int width = 0, height = 0; String stringValueOfC = String.valueOf(c);
BufferedImage temporaryBufferedImage = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) temporaryBufferedImage.getGraphics(); g2d.setFont(getFont()); FontMetrics fontMetrics = g2d.getFontMetrics(); int charHeight = fontMetrics.getHeight(); int charWidth = fontMetrics.stringWidth(stringValueOfC); int charDescent = fontMetrics.getDescent(); Dimension charDimension = new Dimension(charWidth, charHeight+charDescent); g2d.drawString(stringValueOfC, 0, charHeight); BufferedImage bi = temporaryBufferedImage.getSubimage(0, 0, (int)charDimension.getWidth(), (int)charDimension.getHeight());
char[][] bitmapArray = new char[bi.getHeight()][multipleOfEight(bi.getWidth())]; for(char[] ch : bitmapArray) java.util.Arrays.fill(ch, '0'); for(int i = bi.getHeight()-1; i >= 0; --i) { for(int j = bi.getWidth()-1; j >= 0; --j) { if(bi.getRGB(j,i) == -16777216) bitmapArray[i][j] = '0'; else if (bi.getRGB(j,i) == -1) bitmapArray[i][j] = '1'; } } bitmapArray = clearUnusedBits(bitmapArray); ArrayList<Byte> chunkList = new ArrayList<Byte>(); int numChunks = bitmapArray[0].length / 8; for(int lineNumber = bitmapArray.length - 1; lineNumber >= 0; --lineNumber) { String currentLine = new String(bitmapArray[lineNumber]); String[] chunks = new String[numChunks]; getChunks(chunks, currentLine); int[] binaryChunks = new int[numChunks]; getBinaryChunks(binaryChunks, chunks); for(int binaryChunk : binaryChunks) chunkList.add((byte) binaryChunk); height = bitmapArray.length; int x1 = -1, x2 = -1; if( currentLine.contains("1") ) { x1 = currentLine.indexOf('1'); x2 = currentLine.lastIndexOf('1'); int leadingZeros = currentLine.substring(0, x1).length(); int distance = x2 - x1 + 1 + leadingZeros; width = Math.max(width, distance); } } System.out.println("---"); for(char[] ch : bitmapArray) { System.out.println(new String(ch)); } System.out.println("---"); int x0 = 0; int y0 = 0; ByteBuffer buffer = BufferUtils.createByteBuffer(chunkList.size()); for(Byte b : chunkList) buffer.put(b); buffer.flip(); RasterFontInfo rfi = new RasterFontInfo(buffer, width, height, x0, y0); return rfi; } |
And if you need all of the files, they're located here: (2 .java files) https://skydrive.live.com/?cid=f6516fcd92fde78e#cid=F6516FCD92FDE78E&id=F6516FCD92FDE78E!130
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|