Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  LibGDX ShapeRenderer doesn't seem to draw the top-left-most pixel of rectangle?  (Read 809 times)
0 Members and 1 Guest are viewing this topic.
Offline heisenbergman

JGO Coder


Medals: 14


L___ o_ G___ a__ P___


« Posted 2013-06-18 09:13:58 »

Really odd problem... I was using ShapeRenderer for the first time and all was going fine, until I seemed to notice that the rectangle on my menu screen looked odd. So I took a screenshot of it and zoomed in only to find that it was just as I thought: The top-left-most pixel of the rectangle was missing...



Now, I can't imagine what might be wrong with my code since it seems pretty straightforward:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
      ShapeRenderer sr = new ShapeRenderer();
      sr.begin(ShapeType.Line);
      sr.setColor(255/LogapGame.colorConvert,
            255/LogapGame.colorConvert,
            192/LogapGame.colorConvert,
            255/LogapGame.colorConvert);
     
      if(selected == -1){
      } else if(selected == 0){
         sr.rect(102, 91, 103, 15);
      } else if(selected == 1){
      } else if(selected == 2){
      } else if(selected == 3){
      } else if(selected == 4){
      }
      sr.end();


I even took a look at the rect() code in LibGDX and everything seems to be fine there as well:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
   /** Draws a rectangle in the x/y plane. The x and y coordinate specify the bottom left corner of the rectangle. The
    * {@link ShapeType} passed to begin has to be {@link ShapeType#Filled} or  {@link ShapeType#Line}.
    * @param x
    * @param y
    * @param width
    * @param height */

   public void rect(float x, float y, float width, float height){
      if (currType != ShapeType.Filled && currType != ShapeType.Line)
         throw new GdxRuntimeException("Must call begin(ShapeType.Filled) or begin(ShapeType.Line)");
     
      checkDirty();
      checkFlush(8);
     
      if(currType == ShapeType.Line){
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y, 0);
   
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y + height, 0);
   
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y + height, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y + height, 0);
   
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y + height, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y, 0);
      }
      else {
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y + height, 0);

         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x + width, y + height, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y + height, 0);
         renderer.color(color.r, color.g, color.b, color.a);
         renderer.vertex(x, y, 0);
      }
   }


So idk... ... ...help? Undecided

Offline davedes
« Reply #1 - Posted 2013-06-18 12:04:45 »

http://www.badlogicgames.com/forum/viewtopic.php?p=42487#p42487

In your case you should just be using a 2D PNG image instead of ShapeRenderer.


EDIT: Also -- it looks like you are creating a new shape renderer every iteration? Don't do that! Smiley

Offline heisenbergman

JGO Coder


Medals: 14


L___ o_ G___ a__ P___


« Reply #2 - Posted 2013-06-18 12:20:19 »

^ wow, thanks that's very useful information!

It's okay now, rectangle is perfect Smiley

(and I'm not creating ShapeRenderer every iteration anymore, lol [sometimes I get too caught up in making things work that it doesn't occur to me to make things work right -_- thanks again!])

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.

toopeicgaming1999 (29 views)
2014-11-26 15:22:04

toopeicgaming1999 (26 views)
2014-11-26 15:20:36

toopeicgaming1999 (7 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (24 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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!