Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4 5 ... 10
 21 
 on: 2017-12-09 16:18:40 
Started by VxTi - Last post by VxTi
So I'm fairly new to VBO's, but since everyone knows it's wayy faster than immediate mode or display lists, I thought I'd gave it a try. It renders the screen completely white...

My VBO code
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  
public abstract class VBO {


    public static TexVBO create(double vertices[], double texCoords[], Texture tex)
    {
        int vertexId, textureId;
        DoubleBuffer Bvertex, Btexture;

        vertexId = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vertexId);
        glBufferData(GL_ARRAY_BUFFER, Bvertex = dBuf(vertices), GL_STATIC_DRAW);

        textureId = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, textureId);
        glBufferData(GL_ARRAY_BUFFER, Btexture = dBuf(texCoords), GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        return new TexVBO(
                vertexId, textureId,
                vertices.length / 3, texCoords.length / 2,
                Bvertex, Btexture,
                tex.getTextureId(),
                7);
    }

    public abstract void draw();
    public abstract void delete();


    private static DoubleBuffer dBuf(double d[])
    {
        DoubleBuffer buf = BufferUtils.createDoubleBuffer(d.length);
        buf.put(d);
        buf.flip();
        return buf;
    }

}

and my TexVBO code
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  
public class TexVBO extends VBO {

    private int vertexArrayId, textureArrayId, texId;
    private int vexCount, texCount;
    private int drawMode;
    private DoubleBuffer vertexArray, textureArray;

    public TexVBO(int vertexArrayId, int textureArrayId, int vertexCount, int texCount, DoubleBuffer vertexArray, DoubleBuffer textureArray, int texId, int drawMode)
    {
        this.vexCount = vertexCount;
        this.texCount = texCount;
        this.vertexArrayId = vertexArrayId;
        this.textureArrayId = textureArrayId;
        this.texId = texId;
        this.drawMode = drawMode;
        this.vertexArray = vertexArray;
        this.textureArray = textureArray;
    }

    public void draw()
    {
        // Bind the texture

        glEnable(GL_TEXTURE_2D);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texId);




        glEnableClientState(GL_VERTEX_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER, vertexArrayId);
        glVertexPointer(3, GL_DOUBLE, 0, 0);

        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER, textureArrayId);
        glTexCoordPointer(2, GL_DOUBLE, 0, 0);

        // Unbind the array buffer.
        glBindBuffer(GL_ARRAY_BUFFER, 0);

        // Draw the vertices.
        glDrawArrays(GL_QUADS, 0, vexCount);




        // Disable some client states.
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

        // Unbind the texture
        glBindTexture(GL_TEXTURE_2D, 0);
        glDisable(GL_TEXTURE_2D);
    }

    public void delete()
    {
        glDeleteBuffers(vertexArrayId);
        glDeleteBuffers(textureArrayId);
    }

}

What's wrong??

 22 
 on: 2017-12-09 11:56:16 
Started by elect - Last post by elect
MD5 is in!

 23 
 on: 2017-12-09 11:43:21 
Started by Apo - Last post by Apo
Day 9: Heart

Today the Game of the Day is a clone of the great Game "These Robotic Hearts of Mine".

Try to color all hearts.
Solve 10 levels to get the hint of the day

Play with the mouse.


 24 
 on: 2017-12-08 23:55:25 
Started by gurkenlabs - Last post by gurkenlabs

It's out!


Last night we've secretly released v1.0.0 of Naughty Elves! While we are certain that you'll enjoy our little creation, there's still some improvements to be made. So after introducing you to the features of v1.0.0, we'll briefly explain which improvements and fixes you can expect within the next two weeks.
So go ahead and wishlist (or even better, buy) the game now on steam, we have a 10% discount running at the moment!
Naughty Elves on Steam

  • Features in v1.0.0
    • Santa vs. Elves:
      4 Elf types with different perks require you to act strategically. Time your snowballs right and stun elves with your candy cane.
    • Interactive Objects:
      Teleporters, Timed doors and other puzzles will test your aiming and timing skills.
    • Levels:
      Right now, there's 15 levels in the game, gradually increasing in difficulty and variety. We estimate your first playthrough to take about 35 minutes.
    • Achievements:
      Collect 11 steam achievements to brag with among your friends!
    • Controller support:
      Enjoy the game from your couch using your favourite controller.
  • Planned improvements
    • Sounds:
      Soon, each level will feature its individual christmas carol as background music.
      Santa and the Elves are getting more sounds too.
    • Graphics:
      More varied props and environment graphics are on their way!
    • Steam Controller:
      We'll upload a recommended Steam controller config near the end of the weekend so you won't have to figure one out yourself.
    • Levels:
      Maybe not within two weeks, but we'll be adding more levels to the game in the near future.
  • Summary
    It's been an in intense journey to release our first game on steam. The whole project is kind of a test for the capabilities of our engine and a lesson in marketing and digitally distributing a game. Nothing is, however, without flaws, keep in mind that everything you see is made in the free time of two young academics, not professionally. So if you have any issues with the game or other feedback, please let us know so we can improve our work accordingly.

 25 
 on: 2017-12-08 19:07:22 
Started by zngga - Last post by zngga
Thank you for the reply. It lifts my spirits to know I was not only on the right track, but also so close to a solution.
Here is what I have come up with for the EventBus class:

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 EventBus
{
   private Map<Class<? extends Event>, List<MonoCallback<? extends Event>>> eventListeners;

   public <E extends Event> void registerEventListener(Class<E> clazz, MonoCallback<E> listener)
   {
      List<MonoCallback<? extends Event>> list = eventListeners.get(clazz);
      if (list == null)
      {
         eventListeners.put(clazz, list = new ArrayList<>());
      }
      list.add(listener);
   }

   public <E extends Event> void pushEvent(Class<E> clazz, E event)
   {
      if (eventListeners.isEmpty()) return;
      if (!eventListeners.containsKey(clazz)) return;

      List<MonoCallback<? extends Event>> list = eventListeners.get(clazz);
      if (list == null) return;

      for (MonoCallback<? extends Event> listener : list)
      {
         MonoCallback<E> castedCallback = (MonoCallback<E>) listener; // Type Safety: unchecked cast...
         castedCallback.invoke(event);
      }
   }
}


Line 25 produces a type safety warning, is there any good way of getting around, or a better design to avoid this warning. Or must I live with it?

 26 
 on: 2017-12-08 18:04:38 
Started by zngga - Last post by nsigma
First; is there a way to enforce that the Class key and generic parameter in MonoCallback in the eventListeners map are the same?

Yes, in the way that you're doing it!  As long as you don't expose the Map so that only your registration methods can alter it, then you're achieving this.  You can't generify a value based on the key.

Second; when the callback is invoked, that the passed event parameter is ensured to be an instance of the proper Event subclass, not requiring instanceof checks and casting on the listener end? (SomeClass example)

Cast it on the dispatching side after you get it out of the map using Class.cast() with the key.  You may want to consider explicitly passing in the Class as a parameter for the push event method, or storing it in the event, rather than relying on getClass() - eg. gives you more flexibility with the class hierarchy later.

EDIT - by the way, what you're looking at is kind of a Typesafe Heterogeneous Container - https://gerardnico.com/wiki/code/design_pattern/typesafe_heterogeneous_container

 27 
 on: 2017-12-08 17:51:23 
Started by zngga - Last post by zngga
I am trying to create a sort of event bus that can handle multiple different events and their listeners.
The goal is that every event would inherit from a super Event class, the event bus would register that event, and listeners could subscribe to it.
This is probably easier to explain in code:

Event class and possible subclasses
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  
public class Event
{
    public final String eventName;
    public final long timestamp;

    public Event(String name, long time)
    {
        this.eventName = name;
        this.timestamp = time;
    }
}

public class UpdateEvent extends Event
{
    public final double delta;

    public UpdateEvent(double delta)
    {
        super("Event.Update", currentTime);
        this.delta = delta;
    }
}

public class FileUpdatedEvent extends Event
{
    public final File file;

    public FileUpdatedEvent(File file)
    {
        super("Event.FileUpdated", CurrentTime);
        this.file = file;
    }
}


EventBus class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class EventBus
{
    private Map<Class<? extends Event>, List<MonoCallback<? extends Event>> eventListeners = new HashMap<>();

    public <E extends Event> void registerEventListener(Class<E> clazz, MonoCallback<E> listener)
    {
        List<MonoCallback<E> list = eventListeners.get(clazz);
        list.add(listener);
    }

    public <E extends Event> void pushEvent(E event)
    {
        list<MonoCallback<E> list = eventListeners.get(event.getClass());
        for(MonoCallback<E> listener : list)
        {
            listener.invoke(event);
        }
    }
}


Listener
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class SomeClass
{
    public SomeClass()
    {
        instance_of_eventbus.registerEventListener(FileUpdatedEvent.class, (event) -> {
            File file = event.file;
            //do stuff
        }
    }
}


Obviously, the above lacks any sort of polish with null checks and what not, and... of course all fails. But hopefully you understand the point.
So my question is,
First; is there a way to enforce that the Class key and generic parameter in MonoCallback in the eventListeners map are the same?
Second; when the callback is invoked, that the passed event parameter is ensured to be an instance of the proper Event subclass, not requiring instanceof checks and casting on the listener end? (SomeClass example)

I have been messing around with this for quite some time, and have not come to a satisfactory solution, and any online research is so jumbled and confusing that it makes my head hurt.
For the record... I hate generics  Undecided

 28 
 on: 2017-12-08 17:24:21 
Started by SHC - Last post by SHC
Am in Bangalore, India. You thought I moved to a different country for a second right?  Wink

 29 
 on: 2017-12-08 17:19:58 
Started by SHC - Last post by FabulousFellini
Thank you all for the responses. I have opted to the startup as well, and it is extremely fun way (though we are working with PureScript, a functional programming language). I just finished moving to the new city.

What city are you in SHC?

 30 
 on: 2017-12-08 17:16:36 
Started by SHC - Last post by ddyer
Always remember that the employer cares about you the way the farmer cares about the chicken.  You have to watch out for yourself.

Pages: 1 2 [3] 4 5 ... 10
 
Ecumene (143 views)
2017-09-30 02:57:34

theagentd (206 views)
2017-09-26 18:23:31

cybrmynd (290 views)
2017-08-02 12:28:51

cybrmynd (281 views)
2017-08-02 12:19:43

cybrmynd (292 views)
2017-08-02 12:18:09

Sralse (282 views)
2017-07-25 17:13:48

Archive (950 views)
2017-04-27 17:45:51

buddyBro (1088 views)
2017-04-05 03:38:00

CopyableCougar4 (1652 views)
2017-03-24 15:39:42

theagentd (1413 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!