Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / OpenGL Development / Re: Terrain Lighting
|
on: 2011-08-01 20:56:10
|
Yeah. The lighting related code is below; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); ... ByteBuffer temp = ByteBuffer.allocateDirect(20); temp.order(ByteOrder.nativeOrder());
glLightModel(GL_LIGHT_MODEL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(new float[]{0.2f,0.2f,0.2f,1.0f}).flip()); glLight(GL_LIGHT0, GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(new float[]{0.5f,0.5f,0.5f,1.0f}).flip()); glLight(GL_LIGHT0, GL_POSITION, (FloatBuffer)temp.asFloatBuffer().put(new float[]{4.0f,0.0f,8.0f,1.0f}).flip()); |
|
|
|
|
|
2
|
Java Game APIs & Engines / OpenGL Development / Terrain Lighting
|
on: 2011-07-30 23:10:39
|
Hi, I am sure this topic is a very well worn one, but I seem to be having a specific problem. I can't for the life of me seem to be able to get my textured terrain to light properly. Or at all for that matter. I do some vector math to calculate the normals for each point. 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
| private void computeNormals() { if (!computedNormals) { normals = new Vec3f[width][height]; for (int z=0; z<height; z++) { for (int x=0; x<width; x++) { Vec3f sum = new Vec3f(0.0f, 0.0f, 0.0f); Vec3f out = new Vec3f(0.0f,0.0f,0.0f); if (z > 0) { out = new Vec3f(0.0f, getHeight(x,z-1) - getHeight(x,z), -1.0f); } Vec3f in = new Vec3f(0.0f,0.0f,0.0f); if (z < height - 1) { in = new Vec3f(0.0f, getHeight(x,z+1) - getHeight(x,z), 1.0f); } Vec3f left = new Vec3f(0.0f,0.0f,0.0f); if (x > 0) { left = new Vec3f(-1.0f, getHeight(x-1,z) - getHeight(x,z), 0.0f); } Vec3f right = new Vec3f(0.0f,0.0f,0.0f); if (x < width - 1) { right = new Vec3f(1.0f, getHeight(x+1,z) - getHeight(x,z), 0.0f); } if (x > 0 && z > 0) { sum = sum.add(out.cross(left).normalize()); } if (x > 0 && z < height - 1) { sum = sum.add(left.cross(in).normalize()); } if (x < width - 1 &&z < height -1) { sum = sum.add(in.cross(right).normalize()); } if (x < width - 1 && z > 0) { sum = sum.add(right.cross(out).normalize()); } sum = sum.normalize(); normals[x][z] = sum; } } computedNormals = true; } } |
And then I pass it to my function to draw the actual terrain 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
| public void drawTerrain(Terrain terr, float bumpup) { if (terr != null) { for (int z = 0; z < terr.height; z++) { glBegin(GL_QUAD_STRIP); for (int x = 0; x < terr.width; x++) { if (bumpup != 0 && (terr.getHeight(x,z) <= 4.9)) { glColor4f(0.0f, 0.0f, 0.0f, 0.0f); } else if(bumpup == 0) { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } else if (bumpup != 0) { glColor4f(0.0f,0.0f,0.0f,0.2f); } Vec3f normal = terr.getNormal(x, z); glNormal3f(normal.x, normal.y, normal.z); glVertex3f(x+terr.xOffset, terr.getHeight(x,z)+bumpup-20.0f, z+terr.zOffset); if (z != terr.height - 1) { normal = terr.getNormal(x, z+1); glNormal3f(normal.x, normal.y, normal.z); glVertex3f(x+terr.xOffset, terr.getHeight(x,z+1)+bumpup-20.0f, z+1+terr.zOffset); } } glEnd(); } } } |
But I end up with a plain green sheet without definition. If it means anything, each Terrain has a x and z offset value, as the larger terrain is split into chunks. The ground is also textured, but I do not know if that means anything. I would appreciate any help, Jacob  You can see some height change in the above image.  But it cannot be seen without the wireframe overlayed.
|
|
|
|
|
4
|
Java Game APIs & Engines / OpenGL Development / Re: Large Terrain Optimization
|
on: 2011-07-24 19:25:00
|
The problem is that I want the game to be able to be run on a lower-end computer. But mine is most definitely not a lower-end computer  . I have 4GB of RAM, and the pagefile was not being used. My GPU has 1GB of RAM, and I do not think that was the problem, as I wasn't loading much into it. I guess I will just have to limit the number of chunks to draw at once and do some view frustum culling. Thanks for the help!
|
|
|
|
|
5
|
Java Game APIs & Engines / OpenGL Development / Re: Large Terrain Optimization
|
on: 2011-07-23 08:31:55
|
|
Hi! Thanks for the quick response!
I really don't know what a Quadtree is (in terms of 3D graphics) or how I would go about doing anything with them. And having the data be multiresolution probably won't work, but I thank you for your suggestions and I will most definitely think about how I would go about implementing them!
Thanks -Jacob
|
|
|
|
|
6
|
Java Game APIs & Engines / OpenGL Development / Large Terrain Optimization
|
on: 2011-07-23 08:12:52
|
Hi! I am working on my project where I render a very, very large terrain. 40 000 square kilometres. Or about 25 000 square miles. That's the size of Southwestern Ontario and then a bit. Or about 1/6 the size of the United Kingdom. Since this is so massively huge, I obviously couldn't just render it and stick it in a display list. This is because that would take absolutely forever, and would have to do that every time the terrain is changed. That may be a lot, so that is out of the question. I've decided to take the same approach as Minecraft and many other games, by dividing up the terrain into manageable chunks. I then render one of these every frame or so, and store that in a display list. That works really, really well. Up to a point. I was trying to make it so that I could see the entire terrain at once, in a sort of overview mode. I sat and watched the chunks draw and load, and it was fantastic. I still have some work to do with the lighting and the normals, but it looks good. And then this happened.  That was just the beginning. It spiked to 99% of my CPU usage, and it actually made my sound stop working and my wacom tablet driver to freeze and stop responding. I decided that that wouldn't make a very good point in a feature list. And after some fiddling, that brings me here. Asking how any of you managed to wrangle using large terrains. I know that I could just do some trig and such to find out how many chunks are displayed at the current view level and bla bla bla, but I want to see if there are any additional things that I could do, because I want the rendering and graphics to be extremely fast, because the logic is most likely going to be very CPU intensive. So if you have any ideas or solutions for me, just let me know! -Jacob
|
|
|
|
|
8
|
Java Game APIs & Engines / OpenGL Development / [SOLVED] Slick-Util TrueTypeFont Messing with 3D
|
on: 2011-07-22 18:40:44
|
|
Hi all!
I'm trying to draw some debug information as a HUD over my 3D scene, and when I create a TrueTypeFont my entire 3d model goes.....strange. I can see that it is still there, but it is like a ghostly outline. When I comment out the lines where I convert an AWT font to a Slick TrueTypeFont, it goes back to being normal. I was wondering if anybody had any alternatives to using TrueTypeFont or knows why it is doing this.
Thanks, Jacob
|
|
|
|
|
11
|
Java Game APIs & Engines / OpenGL Development / [SOLVED] Terrain Rotation and Zooming without Redraw
|
on: 2011-07-21 20:13:27
|
|
Hi, I'm writing my first 3D game in Java with LWJGL, and I am having some problems with rendering terrain. The terrain is planned to be massive, 100 000 000 squares. About 40 000 square kilometres. I know that I can't draw them all at once, so I started with a much smaller, 200x200 area. I use a heightmap to load height values from, and then use TRIANGLE_STRIPS to draw rows. It can render really fast, but I run into a potentially serious problem. Whenever I try and rotate or zoom in using my keyboard, it flickers. It takes less than a second to draw, but it does flicker. I can image that that will become a very serious problem when I have a massive terrain. It requires me to redraw everything every time the view changes.
I was wondering if there was a way to manipulate the camera view without having to redraw the terrain.
Thanks, Jacob
|
|
|
|
|