Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


RobeeZ

Member Since 11 Sep 2011
Offline Last Active Oct 02 2013 02:27 AM

Topics I've Started

Collision shape for 2D Space game

22 September 2013 - 05:56 AM

Hi!

 

What kind of shape should I use in a 2D topdown space game for collision? I was thinking about AABB, but as the ships are rotating they are not the best option. I was thinking about OBBs or a group of Bounding Circles. I'm more into the circles because of the performance, and I can define a ship's collider more precisely with more circles. I would like to hear your opinion too


OBJ loader for opengl (LWJGL)

09 August 2013 - 06:47 AM

Hi

 

I wrote a simple OBJ loader but the texcoords are messed up somehow. I can't figure out what is wrong. I tried flipping the texture on the Y-Axis, no success. (Here is how my object looks like: http://imgur.com/d8edSyw

 

Code: (FaceData holds the IDs for vertices, normals and texcoords, Vertex class holds the data)

public void parseObj(String path)
    {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(new File("").getAbsolutePath() + "/res/" + path));

            String line = reader.readLine();

            while(line != null)
            {
                if(line.startsWith("v "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    pos.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("vt "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    tex.add(new Vector2f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1])));
                }
                if(line.startsWith("vn "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    norm.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("f "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" ");

                    for(int i = 0; i < vertexStr.length; i++)
                    {
                        String verStr = vertexStr[i].replaceAll("//", "/0/");

                        String[] asd = verStr.split("/");

                        FaceData data = new FaceData();
                        data.vertexID = Integer.parseInt(asd[0]);

                        data.texID = Integer.parseInt(asd[1]);

                        data.normalID = Integer.parseInt(asd[2]);

                        faces.add(data);
                    }
                }

                line = reader.readLine();
            }

            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int i = 0; i < faces.size(); i++)
        {
            Vertex v = new Vertex();
            v.pos = pos.get(faces.get(i).vertexID - 1);

            if(faces.get(i).texID != 0)
            {
                Vector2f t = new Vector2f();
                t = tex.get(faces.get(i).texID - 1);
                t.y = t.y;

                v.texCoord.set(t);
            }
            else
                v.texCoord = new Vector2f(0,0);

            v.normal = norm.get(faces.get(i).normalID - 1);

            vertices.add(v);
        }
    }

Loading OBJ model to VBO

06 August 2013 - 04:14 PM

Hello guys.

 

I came across a problem today. I exported a single cube from blender, and I tried to wrote a simple .obj loader to use. I think my parsing method is okay, but I have problem putting the data into a vbo/ibo. The vertex and fragment shader is working, I used them before. What I get is a deformated cube. Like faces (quad) only got one of the tris drawn.

 

Vertex class contains fields for position, texcoords, and normals

 

FaceData just holds the ID for vertex, texcoord and normal.

public class Model {

    ArrayList<Vertex> vertices = new ArrayList<Vertex>();
    ArrayList<Vector3f> pos = new ArrayList<Vector3f>();
    ArrayList<Vector2f> tex = new ArrayList<Vector2f>();
    ArrayList<Vector3f> norm = new ArrayList<Vector3f>();
    ArrayList<FaceData> faces = new ArrayList<FaceData>();

    int vbo;
    int ibo;

    public int indexCount;

    public Model(String name)
    {
        parseObj(name);

        FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(vertices.size() * 8);

        for(Vertex v : vertices)
        {
            vertBuffer.put(v.getElements());
        }

        vertBuffer.flip();

        vbo = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        IntBuffer indices = BufferUtils.createIntBuffer(faces.size());

        for(FaceData f : faces)
        {
            indices.put(f.vertexID - 1);
            indexCount++;
        }

        indices.flip();

        ibo = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    }

    public void render()
    {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12);
        GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    }

    public void parseObj(String path)
    {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(new File("").getAbsolutePath() + "/res/" + path));

            String line = reader.readLine();

            while(line != null)
            {
                if(line.startsWith("v "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    pos.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("vt "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    tex.add(new Vector2f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1])));
                }
                if(line.startsWith("vn "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    norm.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("f "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" ");

                    for(int i = 0; i < vertexStr.length; i++)
                    {
                        String[] verStr = vertexStr[i].split("/");

                        FaceData data = new FaceData();
                        data.vertexID = Integer.parseInt(verStr[0]);
                        //data.texID = Integer.parseInt(verStr[1]);
                        data.normalID = Integer.parseInt(verStr[2]);
                        faces.add(data);
                    }
                }

                line = reader.readLine();
            }

            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int i = 0; i < faces.size(); i++)
        {
            Vertex v = new Vertex();
            v.pos = pos.get(faces.get(i).vertexID - 1);
            v.texCoord = new Vector2f(0,0);
            v.normal = norm.get(faces.get(i).normalID - 1);

            vertices.add(v);
        }
    }

}


2D top down RPG map design

29 July 2013 - 12:18 PM

Hi!

 

I'm creating some little art for my game, and I don't know how should I make the walls...

 

I uploaded a pic which shows the 2 method, and I can't decide which one looks better in a game. I would go with 2, but it looks like if there was no wall there. I thought about dropping a shadowed, darker piece of wall instead of that "lines"


Learning C++ with OpenGL

25 July 2013 - 09:57 AM

Hi!

 

I'm currently learning modern OpenGL with LWJGL, and I have some experience in Java and C# (2 - 2,5 years). On the other hand, I want to learn C++ too. Is it "hard" to learn both? (C++ and OpenGL too) I have a bit of experience in C++, but I like the managed languages more. But I want to have some more experience in C++ too


PARTNERS