Why this does not work?

I’m trying to visualize openstreetmap data but when I go to render it to the screen, if I change the noFill and stroke it wont render anything. The weird thing is that it works perfectly with those two lines commented. Maybe you can look at it because I don’t know what it could be causing the problem

So this is my code:

import java.util.Map;

XML xml;

XML bounds;
HashMap<String, XML> nodes;
HashMap<String, XML> ways;
HashMap<String, XML> relations;

float minlat;
float minlon;
float maxlat;
float maxlon;

int x;
int y;
int scale;

void settings() {
  xml = loadXML("map.osm");

  bounds = xml.getChildren("bounds")[0];
  nodes = new HashMap<String, XML>();
  ways = new HashMap<String, XML>();
  relations = new HashMap<String, XML>();

  for (XML node : xml.getChildren("node")) nodes.put(node.getString("id"), node);
  for (XML way : xml.getChildren("way")) ways.put(way.getString("id"), way);
  for (XML relation : xml.getChildren("relations")) relations.put(relation.getString("relation"), relation);

  minlat = bounds.getFloat("minlat");
  minlon = bounds.getFloat("minlon");
  maxlat = bounds.getFloat("maxlat");
  maxlon = bounds.getFloat("maxlon");

  x = 0;
  y = 0;
  scale = 400000;

  size((int)((maxlon - minlon) * scale), (int)((maxlat - minlat) * scale), P2D);
}

void setup() {
  stroke(255);
}

void draw() {
  background(0);

  if (mousePressed && mouseButton == LEFT) {
    x += mouseX - pmouseX;
    y += mouseY - pmouseY;
  }

  translate(-minlon * scale + x, maxlat * scale + y);

  for (XML way : ways.values()) {
    PShape wayShape = createShape();
    
    wayShape.beginShape();
    //wayShape.noFill();
    //wayShape.stroke(255);
    
    for (XML nd : way.getChildren("nd")) {
      XML node = nodes.get(nd.getString("ref"));
      
      float lat = node.getFloat("lat");
      float lon = node.getFloat("lon");
      
      wayShape.vertex(lon * scale, -lat * scale);
    }
    
    wayShape.endShape();
    shape(wayShape);
  }

  println("FPS: " + frameRate);`Preformatted text`
}

This is whitout the lines commented:

This is with the stroke only (I should see the lines forming the shapes, but it’s black):

The transformations are done right and I’m not appliyng and scale sho I the the lines should be visible

This is the file:
https://mega.nz/file/8Y521ZCZ#P96Njpd6WUpUjU19XsVmm7DRSI_31ryNoMhUpaP0Dro

Maybe try setting your draw background to 128. Then try setting your wayShape fill and stroke – separately, one at a time – to 0 and 255, and see what happens?

Hello,

With Processing 4.0b1 and 3.5.4…

Using P3D renderer and this:

wayShape.noFill();
wayShape.strokeWeight(2);
wayShape.stroke(color(255, 0, 0));

I got this:

The default and FX3D renderer gave me a solid 60 fps!

I do not know why it does not work with P2D.

Reference for renderers:

:)

2 Likes

Ok, so the default renderer gives a more stable framerate than P2D or P3D and P2D does not work for wathever reason as you said (may be a bug?). Thank you :D