Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  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_LIGHT1);
       glEnable(GL_NORMALIZE);
        glEnable(GL_CULL_FACE);
        glShadeModel(GL_SMOOTH);
       
        ...
     
        //setup lighting
       //add some ambient light. [special lwjgl fixes]
       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());
       
        //add positioned light
       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) {
            //only do it if the normals aren't computed already
           //Vec3f[][] normals2 = new Vec3f[width][height];
           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 (!changeColor) {
            glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        } else {
            glColor4f(0.0f, 0.0f, 0.0f, 0.2f);
        }*/

        if (terr != null) {
            for (int z = 0; z < terr.height; z++) {
                //we are drawing rows of x's
               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);
                    //System.out.println(normal);
                   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.
3  Java Game APIs & Engines / OpenGL Development / Re: Large Terrain Optimization on: 2011-07-25 20:24:50
I don't think I am leaking memory, I just think that I need to optimize a bit and make a few concessions.
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  Cheesy. 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
7  Java Game APIs & Engines / OpenGL Development / Re: Slick-Util TrueTypeFont Messing with 3D on: 2011-07-23 07:25:57
I managed to get it working by doing some messing with my alpha blending code. Thanks!
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
9  Java Game APIs & Engines / OpenGL Development / Re: Terrain Rotation and Zooming without Redraw on: 2011-07-21 20:51:16
Oh. Wait a minute. I guess I WAS doing something fundamentally wrong  Clueless. I changed some stuff around, and now it is so incredibly smooth I just want to hug it. Sorry about that.  Cool
10  Java Game APIs & Engines / OpenGL Development / Re: Terrain Rotation and Zooming without Redraw on: 2011-07-21 20:47:35
Well, I do already use Display Lists. I use one for the terrain itself, but when it is rotated or zoomed, I have to recreate the display list. Unless I have something fundamentally wrong.
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
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (12 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!