Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Dec 2011
Offline Last Active Oct 22 2014 03:19 AM

Topics I've Started

LWJGL/Slick: Strange color state when loading/rendering textures

03 November 2012 - 08:51 PM

Hey guys,

I'm new to OpenGL and I've been playing with LWJGL, and now Slick (since it provides some utilities for loading textures).

I was experiencing a very strange issue in my project, and I was able to reproduce it by slightly modifying the sample code from here:

Here's the code which produces the error:

The important changes are:
  • line 81 (to specify a 16x16 solid red png)
  • lines 113-193 (to draw a 100x100 white rectangle)
Here's the really strange thing.
  • If I disable the texture loading (init()), skip drawing the texture, and go straight to drawing the white rectangle, I get what I expect: A white rectangle in the upper left corner. This is what it looks like: http://i.imgur.com/t4D8n.png
    (Modified code here, which the texture loading/drawing disabled: http://pastie.org/5179294.)
  • If I keep the texture loading/drawing, and then try to draw the same white rectangle, it draws a red rectangle instead.
    So with this code http://pastie.org/5179268, I get this: http://i.imgur.com/bU5pp.png
  • If I repeat step 2 with a 16x16 solid blue png, I get same result, except everything is blue instead of red.
Sample images:
blue - http://i.imgur.com/VjgR1.png
red - http://i.imgur.com/7DVqj.png

Anyone know why this is happening? It seems like some global state is being tainted, but I have no idea how to reset, clean, or avoid it. I've been banging my head against this for days, so any ideas would be greatly appreciated.


Java Swing/AWT, Screen Tearing, and Double Buffering

18 August 2012 - 01:29 PM

Hi there,

I'm working on a 2D platformer game in Java. I'm writing everything from scratch using basic Swing and AWT components.

I'm making good progress on things (collision detection with platforms, level rendering, level scrolling, etc.). However, I've stopped feature development until I can get an issue resolved: jittering/screen tearing.

I've extracted the basic rendering technique from my code base and have been able to (visually) reproduce the error with just a little bit of code.

In my project, I'm using an RK4 integration technique (describe by http://gafferongames...gration-basics/) in the main game loop. For this example, however, I've simplified the update loop to a simple 10 millisecond SwingTimer.

Main.java: https://gist.github.com/3389133
GameWindow.java: https://gist.github.com/3389137
GameCanvas.java: https://gist.github.com/3389138
GameKernel.java: https://gist.github.com/3389139

This example just makes an orange rectangle (the "player") move back and forth across the screen. Even with this simple example, I can see the screen tearing.

I've been reading tons about double buffering techniques (including several forum threads and this series of articles: http://docs.oracle.c.../doublebuf.html). What I've implemented in the code above seems to be the simplest possible way to achieve hardware-accelerated double-buffered rendering. (At least, I'm assuming this taking advantage of hardware acceleration; I'm pretty newb when it comes to graphics programming.) I've tried other more sophisticated approaches suggested in the Java documentation of BufferStrategy (http://docs.oracle.c...erStrategy.html). I've followed this almost to the letter, and even added a call to Toolkit.sync() (a suggestion from a thread I read). Here's basically what I have in my game right now: https://gist.github.com/3389202

Unfortunately, all of this fancy code doesn't seem to affect any change (good or bad), compared to the simple double buffering technique I pasted above. At this point, I'm kind of doing things in "cargo cult" fashion: thrashing around until _something_ works.

I could use some help. Can anyone tell me what I'm doing wrong? Or perhaps the better question to ask first is, can anyone reproduce this screen tearing issue with the code I posted above (so I can rule out the possibility of this just being an issue with my machine)?

Platform info:

Mid 2010 MacBook Pro
OS X 10.7.4
JDK 1.6.0_33
NVIDIA GeForce GT 330M 256mb
1680 x 1050 display

Any tips are appreciated. Cheers!

Collisions with non-rectangular geometry

30 December 2011 - 05:59 AM

Hi there,

I'm currently working on my first game from scratch for the learning experience and for fun. It's a simple 2D platformer written in Java using basic Swing and AWT components for the graphics. Nothing fancy.

For the sake of simplicity, all of the entities in my game (which, at the moment, only consists of the player character and terrain/platforms) are represented by rectangles. This makes collision detection and response (I'm using a simple projection method) incredibly simple: All entities are rectangles and thus all collision intersections are rectangles. Collision intersections are created using Rectangle2D.createIntersection() (http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Rectangle2D.html#createIntersection(java.awt.geom.Rectangle2D).

For this project, I don't plan on using anything more sophisticated than this.

However, for future projects I'm curious to know about how collisions are handled with other types of geometry, such as triangles. I imagine this is problem that you would need to solve in order to have sloped terrain, right? I've done a bit of searching on the web and so far haven't come up with much. Can anyone suggest any articles or other resources that deal with these kind of collisions?