Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 5:13 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: dashed outline shapes?
PostPosted: Mon May 21, 2012 6:07 am 
Offline

Joined: Sun Jan 29, 2012 3:35 am
Posts: 17
hi, simple question and sorry if its a bit obvious but how do you set the line type to dashed or dotted for shapes?
specifically for circles, and they'll be fairly rapidly expanding and contracting so the solution needs to be flexible

thanks


Top
 Profile  
 
PostPosted: Mon May 21, 2012 6:27 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
You could achieve this with GL stippling.
Code:
      int spacing = 4;
      short pattern = (short) 0xAAAA;
      // enable line stippling
      GL11.glLineStipple(spacing, pattern);
      GL11.glEnable(GL11.GL_LINE_STIPPLE);

      // draw all of our dotted-line shapes
      // as long as they use GL_LINES it will work
      g.draw(s);
      g.draw(s2);

      // disable line stippling
      GL11.glDisable(GL11.GL_LINE_STIPPLE);


More info and other pattern examples:
http://fly.cc.fer.hr/~unreal/theredbook/chapter02.html

Problems:
  • It's deprecated OpenGL, which means it won't be very well supported by drivers in the future.
  • Drivers will tend to implement it slightly differently; so don't expect your dotted lines to look identical on all systems.


Top
 Profile  
 
PostPosted: Tue May 22, 2012 7:30 am 
Offline

Joined: Sun Jan 29, 2012 3:35 am
Posts: 17
thanks, shame there's not a 'cleaner' way but i had to get into OpenGL sometime

Speaking of which, besides performance how would you guys say direct oGL calls might improve a slick game, and are there any other resources (info) focusing only on the Slick-compatible/useful parts?


Top
 Profile  
 
PostPosted: Wed May 23, 2012 5:01 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
GreyIV wrote:
Speaking of which, besides performance how would you guys say direct oGL calls might improve a slick game, and are there any other resources (info) focusing only on the Slick-compatible/useful parts?

For a start: a wider range of blend modes, sorting sprites based on the depth buffer (i.e. hardware), masking with the stencil buffer, collision detection done on GPU, dynamic shadows/lighting, explosion effects, blurring/depth of field, normal mapping, etc. These are all possible using lower level OpenGL/GLSL alongside Slick.

Unfortunately, there aren't many resources yet. But Slick is not doing a whole lot that would interfere with low-level GL calls, so pretty much anything can be "compatible." You just need to take a few precautions before you start using GL.

  • If you're using ScalableGame, you should account for the scaling factor at all times (vertices, matrix transforms, etc).
  • Slick caches the last bound texture to avoid redundant glBindTexture/glEnable calls. If you change these states using low-level OpenGL, you should use TextureImpl.unbind() (which clears the last bound texture) or TextureImpl.bindNone() (which clears the last bound texture, and then glDisables texturing).
  • Organize your code like so:
    Code:
    ... Slick code ... //don't use GL11/etc. calls here
    Renderer.get().flush(); //flush the renderer before using GL11 calls
    ... GL code, e.g. glBlendFunc ...
  • When you change a state/attribute (like viewport), generally it would be a good idea to change it back before continuing Slick rendering. For example, if you're changing depth/alpha/blending, use glPushAttrib to revert the state.
  • When in doubt, use SlickCallable to be extra safe (at the expense of performance; it requires a lot of state changes).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group