Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (681)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (744)
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  
  pixel perfect rendering in 2d  (Read 2617 times)
0 Members and 1 Guest are viewing this topic.
Offline Aramaz

Junior Devvie

Java Games Rock!

« Posted 2006-02-17 23:07:02 »

The problem I have is that when the rendering has to be scaled because a different screen mode than the optimal one is used, the 2d result isn't pixel perfect. It's not noticeable when moving around at high speeds, but when going slowly sharp lines in textures appear and disappear by every small incremental movement.

ortho is set to 1280x960, if the actual screen resolution is the same, everything renders pixel perfect (I only allow integer rendering positions).

any other resolution the rendered image is scaled on the fly, I guess a solution would be to set ortho same as screen res, and then multiply every position, width etc with screenWith/1280 (and likewise for y). And only allow for integer positions...

It's much neater to just use glOrtho to have it appear the same... any ideas for making it pixel perfect when using the same ortho for all resolutions? (The effect occurs due to pixels not appearing on integer coordinates)

Play XSW:
Offline chaosdeathfish

Junior Devvie

Projects: 1

« Reply #1 - Posted 2006-02-19 00:59:51 »

Most GUIs seem to use a layout manager of some kind to arrange components in the window - so your widgets are the same pixel size at any resolution, but get moved around as you suggest to fill the available space properly.
Offline Aramaz

Junior Devvie

Java Games Rock!

« Reply #2 - Posted 2006-02-19 15:00:33 »

Well, in this case it's a game screen, and you should see the same view of the world on any screen resolution chosen, the only difference is that the details in the textures are higher at higher screen res.

Anyways, I set the ortho to the same as screen res and just did the multiplication as I mentioned, it was very easy to change the code to that, and now the scaling effects are gone Smiley

So problem is solved, and everyone is happy  Cool

Play XSW:
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #3 - Posted 2006-02-19 17:09:09 »

I read this topic and immediately the figure 0.375 popped into my head. Reading appendix H of the Red book has revealed why:

If exact two-dimensional rasterization is desired, you must carefully specify both the orthographic projection and the vertices of primitives that are to be rasterized. The orthographic projection should be specified with integer coordinates, as shown in the following example:

gluOrtho2D(0, width, 0, height);

where width and height are the dimensions of the viewport. Given this projection matrix, polygon vertices and pixel image positions should be placed at integer coordinates to rasterize predictably. For example, glRecti(0, 0, 1, 1) reliably fills the lower left pixel of the viewport, and glRasterPos2i(0, 0) reliably positions an unzoomed image at the lower left of the viewport. Point vertices, line vertices, and bitmap positions should be placed at half-integer locations, however. For example, a line drawn from (x1, 0.5) to (x2, 0.5) will be reliably rendered along the bottom row of pixels int the viewport, and a point drawn at (0.5, 0.5) will reliably fill the same pixel as glRecti(0, 0, 1, 1).

An optimum compromise that allows all primitives to be specified at integer positions, while still ensuring predictable rasterization, is to translate x and y by 0.375, as shown in the following code fragment. Such a translation keeps polygon and pixel image edges safely away from the centers of pixels, while moving line vertices close enough to the pixel centers.

glViewport(0, 0, width, height);
gluOrtho2D(0, width, 0, height);
glTranslatef(0.375, 0.375, 0.0);
/* render all primitives at integer positions */

Does this help in your situation?
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Hydroque (42 views)
2016-06-22 02:17:53

SwampChicken (44 views)
2016-06-20 13:22:57

SwampChicken (43 views)
2016-06-20 13:22:49

SwampChicken (37 views)
2016-06-20 13:22:26

Hydroque (79 views)
2016-06-15 08:22:50

Hydroque (71 views)
2016-06-13 06:40:55

DarkCart (191 views)
2016-05-29 02:30:33

Hydroque (159 views)
2016-05-26 14:45:46

Mac70 (167 views)
2016-05-24 21:16:33

theagentd (150 views)
2016-05-14 18:38:35
Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47 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‑
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!