Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (701)
Games in Android Showcase (203)
games submitted by our members
Games in WIP (774)
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] 2 3
1  Game Development / Newbie & Debugging Questions / Re: Messed up Textures on: 2016-11-17 19:35:33
Thanks I tried " (re)build the normals and check for hidden/double vertices/edges"
and that seems to have sorted it.
2  Game Development / Newbie & Debugging Questions / Messed up Textures on: 2016-11-17 00:42:07
I have a problem with my models not showing up the textures correctly.



The top left image shows a test model with the messed up texture. The bottom left shows the model in blender as it should look. The right hand images shows another model I made, loaded in exactly the same way, but for some reason does not have the same problem. I'm not sure if it is a model export problem or opengl code bug.

If anyone has had a similar problem before and can suggest something, that would be great.

3  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-11-09 23:47:40


Today I implemented a grass shader using a geometry shader that creates billboards on the fly. Points are passed in each frame for a set distance around the player and then the geometry is generated...the quads are then alpha blended with distance so they don't pop as they are first rendered. I'll have to improve it in the future but for now I'm happy. My only issue is that I'm not totally happy with are the quads up close to the camera, as they clash with the ground a bit obviously. I plan to change the colour of each quad to blend better with the terrain texture below it.
4  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-10-20 22:02:18
To day I implemented normal mapping for my multi-textured terrain. Still have a lot of improving to do, but just happy to have something to show for it.



Edit: replaced picture after fixing the normal mapping fragment shader. Now the proper normal maps are applied to the right textures. Before they where all being mixed together.
5  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-10-11 13:06:07
Guess what I've been doing.. other than changing nappies and the rest. Yes that's right yet more jni video tutorials... Roll Eyes even though no one asked for them... and most likely no one wanted them.. and they are probably not very good, here they are! Pointing

Ever wondered how to use jni to pass int pointers in to a function and return a value. Well here it is.

https://youtu.be/yHlcgTtuVRo

Ever wondered how to  return a String from a native function or use native callbacks. Well here it is.

https://youtu.be/I2PHwFJsAGY
6  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-10-06 22:25:17
I don't think I have ever been this productive before, but I just uploaded another tutorial on jni and glfw. This time I added OpenGL to the mix. Two whole functions...  Pointing

https://youtu.be/sh1VsMubKRw

I'm not expecting anyone to actually watch them, I'm mostly doing to it to clarify it for myself (The best form of learning is teaching other people)   But if anyone finds it useful that would be excellent.  Grin
7  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-10-05 18:45:51
Finally finished a tutorial video on jni it has taken all week to make even though it is only about 20 mins long. It seems video making is an iterative process as much as programming.

https://youtu.be/6IqCyxknrTc
8  Game Development / Newbie & Debugging Questions / Re: Should the same objects be made in the same class? on: 2016-09-29 08:35:05
Or have a badguy class and spawn class that does the job of distributing the bad guys.  I would put them in an array so they can be iterated through.  
9  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-09-29 08:24:19
Wrote a method to load a horizontal cross shape cubemap png,  instead of needing 6 separate texture files.  Now I can just export straight out of genetica,  without having to first manually divide it up. 
10  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-09-22 09:08:40
Just listened to an iteresting discussion on zeno paradoxes. http://www.bbc.co.uk/programmes/b07vs3v1

Starts after 2 mins.

Edit: should work now
11  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-09-15 13:38:36


Working on quadtrees and only rendering entities close to the player.
12  Discussions / Miscellaneous Topics / Re: What I did today on: 2016-03-22 23:29:34
Rewrote my COLLADA library, it now reads and writes the files. Now writing a builder class to make using it a lot easier.
13  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java Library written IN Java on: 2016-03-22 18:39:42
I use JNA so I can get the access to native code, but don't have to write any myself. I have an OpenGl library, use glfw3 for windowing....
14  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-14 10:33:40
Added zbrush polypaint colour loading to my *.obj loader. don't ask why, its just because i can Grin
15  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-11 13:01:04
Added generation of flat normals and smoothing normals for my mesh loading class. Working on generating tangents next
16  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-12-02 09:33:09
Doing a total rewrite of a 'complete' collada importer! Grin
17  Game Development / Newbie & Debugging Questions / Re: Clean code & Smooth development on: 2014-10-16 12:56:58
Readability Cool! I try to keep method and class to a size that I can understand in one viewing. If I have to think too hard about it I break the task up into methods that can be understood. I agree that most of the time a class should do one thing, a balance needs to be attained, the code should work for you.

If a section of code is used more than once it often goes in a method Pointing. If there are a lot of helper methods in a class that are useful in general they get put in a new class for reuse, tested and documented.

Divide and conquer ftw! Grin
18  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-10-16 08:31:35
I made a simple class that extracts the native files from a jar, for the operating system and platform. I changed my asset loading practice so that I can load media from jar files instead of separate folders. So it is now much easier to package up my program and distribute. Also I added the ability to use JavaFX with my game engine.
19  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-10-14 08:11:13
@HeroesGraveDev Have you considered using fractal patterns as well? They can help produce more natural landscapes.
20  Discussions / General Discussions / Re: What is wrong with reinventing the wheel? on: 2014-10-08 11:29:45
If everyone just used the same wheel we would all still be using wagon wheels.  We would never have airplanes if everyone just carried on using the same old tec. Remember that crisis is the mother of invention. Even if you have a deadline sometimes that is when you produce something new and fantastic. Many inventors have been people who just having lost their job have a great idea and choose to go for it.
21  Game Development / Newbie & Debugging Questions / Re: Exporting Slick Game without JarSplice on: 2014-10-06 19:01:38
Native packaging in Netbeans using Inno 5 setup. Creates an exe installer which packages a java runtime as well. Works really well and easy to use. Also alternative native packaging for Linux and mac.
22  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-10-03 23:25:17
Now my collada loader supports multiple materials Grin (phong so far) in the same mesh.  My engine can render just the diffuse textures. Still ironing out the bugs Emo with the skinning some models animate fine while others are a bit odd Cranky.

I've found that if I get stuck one part, if I switch to another bit of the engine and work on that and then go back to the other part again I make more progress.

Making the loader for myself is a lot easier than trying to design a stand alone library that could be used in anyones project, so I might need some help with that if other people wanted to use it. I'm not planing on supporting every part of the specification as I don't need it, but may be others could complete it. Or just use it to make their own.
23  Discussions / General Discussions / [solved]Re-scaling images on: 2014-10-03 10:36:56
What is the best way in java to scale an image ?

Say you wanted to load an folder of images and for each one you want the image to be made square whatever the dimensions :
 eg rescale the width of 256 so it matches the height of 512. It needs to be interpolated (eg Cubic) and not just stretched. Preferably in console mode.

[edit]Nevermind found out how to do it. Roll Eyes
24  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-09-25 21:42:15
@princec Its still a bit fragile and not fully tested. Plus it doesn't support everything Collada offers,  I might release it when done. But for now my priority is to get my game engine done.
25  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-09-25 19:07:15
Woot yay! .. finally got my collada loader working properly with skinning Grin.
26  Game Development / Newbie & Debugging Questions / Re: Collada format interleaved index buffer? on: 2014-09-21 12:32:20
/facepalm given that the collada format isn't in the format of an interleaved array then no. you have to convert it as described.
27  Game Development / Newbie & Debugging Questions / Re: Collada format interleaved index buffer? on: 2014-09-21 10:46:45
Next step is in opengl to use the interleaved buffer.
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  
 int VERTEX_POS_SIZE = 3;
int VERTEX_NORMAL_SIZE = 3;
int FLOAT_SIZE_BYTES = 4;
stride = FLOAT_SIZE_BYTES * VERTEX_POS_SIZE +VERTEX_NORMAL_SIZE ; // length of the vertex 3 + 3


// create buffer
int vertBuffer= glGenBuffer();

glBindBuffer(GL_ARRAY_BUFFER, vertBuffer);
      glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);//vertices are what what made in the previous post.
      glBindBuffer(GL_ARRAY_BUFFER, 0);

in indexBuffer = glGenBuffer();
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW);//indices where also made in the previous post.
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

//bind buffer
glBindBuffer(GL_ARRAY_BUFFER, vertBuffer);
 

glEnableVertexAttribArray(shader.getPositionHandle()); // however you get your handles your self
glEnableVertexAttribArray(shader.getNormalHandle()); // dito


int offset =0;

            glVertexAttribPointer(shader.getPositionHandle(),
                            VERTEX_POS_SIZE, GL_FLOAT, stride, 0);      
            offset += FLOAT_SIZE_BYTES *3;
     
            glVertexAttribPointer(shader.getNormalHandle(),
                            VERTEX_NORMAL_SIZE, GL_FLOAT, stride, offset);            
            offset += FLOAT_SIZE_BYTES*3;

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
//draw
glDrawElements(GL_TRIANGLES, vertices.length, GL_UNSIGNED_SHORT, 0);


// unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(shader.getPositionHandle());
glDisableVertexAttribArray(shader.getNormalHandle());


My code presumes the verts and indexs are in the format your methods can take.. you might need to convert to FloatBuffer or IntBuffer first.

This code is not the latest as it works for GLES2 so I'm sure there is a proper way to do it for 4+
28  Game Development / Newbie & Debugging Questions / Re: Collada format interleaved index buffer? on: 2014-09-21 10:24:09
I take it you want to parse the <triangle> node of a collada file. <p> is the indexes 
1  
<p>2 0 0 0 1 0 3 1 2 1 1 1<p>


so I presume you have parsed the
1  
<input semantic="VERTEX" source="#your-mesh-vertices" offset="0"/>


and  also
1  
<input semantic="NORMAL" source="#your-mesh-normals" offset="1"/>


1  
int normal_offset =1;


so with that in mind you need a class to hold your triangle data I call mine Face but you can call it triangle if you like.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class Face 
{

// Indices for each vertex point, 3 points for each face.
      int v1, v2, v3, n1,n2, n3;

                public Face(int v1, int v2, int v3){
         this.v1 = v1;
         this.v2 = v2;
         this.v3 = v3;
   
      }
               
      public void setNormal(int n1,int n2, int n3)
                {
         this.n1 = n1;
         this.n2 = n2;
         this.n3 = n3;
      }
}
               


You need the stride of your array which is the number of inputs.. 2 in this case.

1  
int triStride =2;




So putting it together we can loop through p to save the array in a format that is easy to use.

1  
2  
3  
4  
5  
6  
7  
8  
9  
for (int i = 0; i < p.length;i+= 3*triStride)
        {
               Face face = new Face(p[i],p[i+triStride],p[i+triStride+triStride]);

               face.setNormal(p[i+normal_offset],
                                      p[i+normal_offset+triStride],
                                      p[i+normal_offset+triStride+triStride]);
               facesArrayList.addFace(face);
        }        


With the faces created you can now decide if you want to create an interleaved index buffer or just separated type. I use interleaved so I explain that one.

I use a class called Vertex to store the data in a per vertex way instead of per face, which is then used to create an interleaved buffer without repeated vertex data. I've striped out all the checks that I usually make for brevity, also usually the vertex class has UV color and bone data included.

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  
public class Vertex {
    private final float[] xyz = new float[3];
    private float[] norm;
    private int size;

   public void setVertex(Vec3 vec){
        xyz[0] = vec.x;
        xyz[1] = vec.y;
        xyz[2] = vec.z;
        size = 3;
    }
   
    public void setNormal(Vec3 vec){
        norm = new float[3];
        norm[0] = vec.x;
        norm[1] = vec.y;
        norm[2] = vec.z;
        size +=3;
    }

public float[] getVerts(){
    float[] verts = new float[size];              
    int i = 0;                
    System.arraycopy(xyz, 0, verts, i, 3);
    i += 3;
    System.arraycopy(norm, 0, verts, i, 3);
    i += 3;// for other data not included here....
    return verts;
}


Vertex also overrides the equals method and hashCode

The next step is to take the ArrayList of faces, ArrayList of verts and ArrayList of norms; ( which I presume you have already filled from the <mesh> nodes<source id="your-mesh-positions"> and <source id="your-mesh-normals"> respectively), and put them in to the a vertexs ArrayList, and also put indexs into an indexes ArrayList (demonstrated next).


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  
 for(Face each : faces)
            {
                 
                // vertex 1 -----------------------------------------------
                Vertex v = new Vertex();              
                v.setVertex(verts.get(each.v1));
                v.setNormal(norms.get(each.n1));                  

// check to see if the vertex already exists, if it does just ad the index to the index array if not add it do both.              

                short index = (short) this.vertexs.indexOf(v);      
                if (index < 0) {                    
                    this.vertexs.add(v);
                    index = (short) (this.vertexs.size() - 1);
                }
                indexes.add(index);

                // vertex 2 ------------------------------------------------
// do the same for each vertex in the face.

                v = new Vertex();
                v.setVertex(verts.get(each.v2));                
                v.setNormal(norms.get(each.n2));  

                index = (short) this.vertexs.indexOf(v);        
                if (index < 0) {                      
                    this.vertexs.add(v);
                    index = (short) (this.vertexs.size() - 1);
                }
                indexes.add(index);

                // vertex 3      -------------------------------------------

                v = new Vertex();
                v.setVertex(verts.get(each.v3));
                v.setNormal(norms.get(each.n3));  
 
                index = (short) this.vertexs.indexOf(v);        
                if (index < 0) {                    
                    this.vertexs.add(v);
                    index = (short) (this.vertexs.size() - 1);
                }
                indexes.add(index);
                }
            }
         }


The last part is for you to decide which you put the data straight into a FloatBuffer and IntBuffer or just use regular java arrays. It depends on what you want to do with the data. I personally convert it to my own model format and save in a binary file to load later, but you might want to check that your code works first and view your model.

You can get the data into arrays with this following code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
            int size = vertexs.get(0).size();

            float[] vertices = new float[vertexs.size() * size];      

            // puts the vertex data in to a float array.
            for (int i = 0;i < vertexs.size();i++){
                System.arraycopy(vertexs.get(i).getVerts(), 0, vertices, i*size, size);        
            }

            // put the indexes into an short array
            short[] ind = new short[indexes.size()];
            for (int i = 0; i < indexes.size();i++){
                            ind[i] = indexes.get(i);            
            }



Incidentally you can use the same code to parse <polylist>  so long as the <vcount> node only contains 3s (triangulate from your modeling program first)
29  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-09-16 16:35:06
Managed to write a shader to show bone weights.

 

Still trying to get my skinning code to work....
30  Discussions / Miscellaneous Topics / Re: What I did today on: 2014-08-17 13:44:30
Can now display normals in my render engine

Pages: [1] 2 3
 
ral0r2 (192 views)
2016-11-23 16:08:26

ClaasJG (332 views)
2016-11-10 17:36:32

CoffeeChemist (426 views)
2016-11-05 00:46:53

jay4842 (477 views)
2016-11-01 19:04:52

theagentd (488 views)
2016-10-24 17:51:53

theagentd (476 views)
2016-10-24 17:50:08

theagentd (434 views)
2016-10-24 17:43:15

CommanderKeith (432 views)
2016-10-22 15:22:05

Roquen (405 views)
2016-10-22 01:57:43

Roquen (302 views)
2016-10-17 12:09:13
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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!