Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Magic sequences of operations  (Read 1387 times)
0 Members and 1 Guest are viewing this topic.
Offline greghall

Senior Newbie




Java games rock!


« Posted 2005-02-27 13:35:04 »

I was having a problem with a very short program that draws a bitmap and a pixel image.

For the bitmap, I would set the raster position, set the color, then draw the bitmap 3 times in a row, to get three light blue-green letter F's in the lower left corner.

For the pixel image, I would draw it centered over the mouse location. If the pixel image is going over the edge of the bottom or left sides, some extra work is performed so that only the part that fits on the screen is copied, so the raster position is always on the screen.

I found that when the pixel image started to slide off the bottom or left side, when the extra steps are taken, the bitmap would appear in white, even if I picked a different color.

I also found that it didn't matter if I executed the bitmap code before or after the pixel image code - the bitmap would still be white.

Note that nowhere in my code did I ever set the color to white.

I eventually discovered that by setting the bitmap color first, THEN setting the raster position and drawing it, the problem went away - the bitmap always appears in the desired color, regardless of what the pixel image is doing.

Is this something that occurs a lot in OpenGL - needing to find the correct magic sequence of operations?

Does this kind of thing depend on the video card, OpenGL driver, and/or operating system?

Is there any site with some general advice about what sort og gotchas to look out for?

I'm using OS X.

Tx.
Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #1 - Posted 2005-02-28 07:24:37 »

OpenGL is a state machine, so any state you set for previous operations persists. Equally, anything unset is pretty much undefined. If you don't set a colour and you get weird colours then it's your own fault. :p

On a more practical note, this basically means you've got to remember to set appropriate state, and in general disable stuff after you've finished working with it (ie, always assume a single, well-known state and if you change it, change it back).

If you want a totally robust solution you'll need a high-level renderer with drawing state encapsulated in rendering style objects / settings.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline greghall

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-02-28 20:49:47 »

In terms of returning to a well-known state, I take it that it is better to do this with glPushAttrib and glPopAttrib?

Would it be a significant performance hit to just always use glPushAttrib with GL_ALL_ATTRIB_BITS, just to make life easy?

Is there any real performance hit if, for example, you have 100 objects that all turn alpha blending on and off individually, rather than turning it on once at the beginning?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2005-02-28 22:49:00 »

Setting the state can be a very costly operation. It depends on the state and possibly the driver. I remember that texture attributes were very slow to set. Although it is always best to profile this yourself, I have to say that reducing state switches is always a porformance priority.

Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #4 - Posted 2005-03-01 06:15:14 »

I don't tend to use pushAttrib, 'cos I have it all hidden inside rendering classes mostly (and 'cos I only use simple state most of the time). Generally though the only really expensive state changes are texture binds and vertex/fragment program binds.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1594 views)
2018-06-10 19:43:48

EgonOlsen (1695 views)
2018-06-10 19:43:44

EgonOlsen (1150 views)
2018-06-10 19:43:20

DesertCoockie (1578 views)
2018-05-13 18:23:11

nelsongames (1178 views)
2018-04-24 18:15:36

nelsongames (1701 views)
2018-04-24 18:14:32

ivj94 (2467 views)
2018-03-24 14:47:39

ivj94 (1683 views)
2018-03-24 14:46:31

ivj94 (2767 views)
2018-03-24 14:43:53

Solater (905 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!