Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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 2228 times)
0 Members and 1 Guest are viewing this topic.
Offline Aramaz

Junior Duke




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: www.xsw.se
Offline chaosdeathfish

Junior Duke


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 Duke




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: www.xsw.se
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Duke


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:

Quote
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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!