SU2024 API Problem with view.draw2d GL_POINTS

I encountered an unexpected problem with my plugin in the new version of SketchUp 2024.
What I do: I create buttons in the workspace, on them I need to draw some icons. I do this using my own workarounds and drawing icons with pixels. This method worked in all versions of SketchUp until 2024.
The rendering method that always worked before:

def print_pic(pic,lt_x,lt_y, view)
	if pic!=nil
		pic.each do |color|
			view = Sketchup.active_model.active_view if view==nil
			if (color!=nil)&&(view!=nil)
				rgbcolor = Sketchup::Color.new(color[:color].red, color[:color].green, color[:color].blue, color[:color].alpha)
				rgbcolor.alpha = 155
				view.drawing_color = rgbcolor
				pts = []
				to_z = color[:x].length-1
				x_arr = color[:x]
				y_arr = color[:y]
				for i in 0..(to_z)
					x = x_arr[i]+lt_x
					y = y_arr[i]+lt_y
					pts << (Geom::Point3d.new(x,y,0))
				end
				view.draw2d GL_POINTS, pts if pts.length>1
			end
		end
	end
end

An example of a picture that is fed into this method:

pic = [{:color=>Sketchup::Color.new(255,20,20),:x=>[24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25],:y=>[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,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]},{:color=>Sketchup::Color.new(140,20,20,140),:x=>[24,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26],:y=>[43,43,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]}]

Result in SketchUp 2024:

Result in SketchUp of any other version:

The problem is in the line: view.draw2d GL_POINTS, pts
Namely, in the GL_POINTS constant, it draws in model space, and not in monitor screen space. The rest of the constants (GL_QUADS, GL_LINE_STRIP, GL_TRIANGLES …) seem to work fine.

I recently (a couple of days ago) tried using GL_POINTS in Ruby code to draw in 2D screen space and did not see this error of it drawing in model space.

I abandoned using GL_POINTS because the line width was being scaled by UI.scale_factor and this clashed with the rest of what I was drawing using GL_QUADS, which are not modified by display scaling.


(1) Can you reduce it down to a reproducible code snippet, so others can try ?

(2) Do you see a difference between the old OpenGL engine and the new engine using DirectX 12?

(3) What Nvidia graphics driver are you using?

(4) Your forum profile is out of date. It says you are using SU2020 and the web-based edition which does not have a Ruby API.


Please use 2 space Ruby indentation when posting code and use multiple lines for large arrays and parameter list so readers do not need to scroll horizontally to read your code.
Examples …

        rgbcolor = Sketchup::Color.new(
          color[:color].red,
          color[:color].green,
          color[:color].blue,
          color[:color].alpha
        )

… and …

pic = [
  {
    :color => Sketchup::Color.new(255,20,20),
    :x => [
      24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
      24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,
      25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
      25,25,25,25,25,25,25,25
    ],
    :y => [
      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,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
    ]
  },
  {
    :color => Sketchup::Color.new(140,20,20,140),
    :x => [
      24,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
      26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26
    ],
    :y => [
      43,43,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
    ]
  }
]

Most Ruby coding style guidelines suggest always put spaces before and after operator characters (=, ==, !=, => &&, ||, etc.,) and surround method call parameters with parenthesis for all instance method calls and module method calls (unless the method is from Kernel, Object, BasicObject, Module and Class; … i.e., these methods are the only ones that have “keyword status”.)

The object is for humans to be better able to read your code. (You are really helping to speed up the parser by cramming everything together.)

I recently (a couple of days ago) tried using GL_POINTS in Ruby code to draw in 2D screen space and did not see this error of it drawing in model space.

Have you tried this in SketchUp 2024? I see the problem only in this version. All other versions work as expected, given the API documentation Class: Sketchup::View — SketchUp Ruby API Documentation

I abandoned using GL_POINTS because the line width was being scaled by UI.scale_factor and this clashed with the rest of what I was drawing using GL_QUADS , which are not modified by display scaling.

I think I’ll also have to reconsider the way I display these pictures.

(1) Can you reduce it down to a reproducible code snippet, so others can try ?

I don’t see any point in reproducing the code for testing, since the main problem lies in the API method “view.draw2d GL_POINTS, pts”. And if it previously worked (and works now) in all versions of SketchUp and does not work in the latest version, then the problem is in the latest version (I think so)

(2) Do you see a difference between the old OpenGL engine and the new engine using DirectX 12?

Switching the engine in SketchUp 2024 settings does not give any result. Yes, after the switches I restarted SketchUp and tried to return the selected engine to its place (in different combinations, as you recommended in other posts and user/developer questions). After I checked all the combinations myself (which I considered necessary), I decided to publish my question. But not so that you can help me write the code, but simply so that the developers will once again check their API and how the GL_POINTS=0 constant is processed in the view.draw2d method. If everything is correct and there are no errors, then I will look for a way to adapt to the new rules.

(3) What Nvidia graphics driver are you using?

Current settings (problem persists):
Renderer information:
Graphics Engine Name: New Graphics Engine
Graphics API: DX12
Graphics Driver Version: 32.0.15.5585
GPU Name: NVIDIA GeForce RTX 2070

(4) Your forum profile is out of date. It says you are using SU2020 and the web-based edition which does not have a Ruby API.

I don’t think this will solve the problem. I think this has nothing to do with view.draw2d GL_POINTS, pts

Please use 2 space Ruby indentation when posting code and use multiple lines for large arrays and parameter list so readers do not need to scroll horizontally to read your code.
Examples …

Thanks for the tips on code formatting, but I don’t really need them, I’m my own developer, and I write as it suits me. The plugin code has already exceeded 100 thousand lines, and I have come to the conclusion that 4 spaces (tab) are personally more convenient for me than 2. The code that I showed is just for understanding that there is nothing supernatural in it, it uses a standard API method that works in all SU until 2024, and does not work in the latest version.

Personally, I have no complaints about you DAN; on the contrary, over the past 10+ years I have learned a lot from your recommendations and advice. It seems that you are the only author of SketchUp, and I am the only author of my plugin for it ))) Thank you!!

Except that I did not see this in 2024 when I was using draw2d with GL_POINTS.
But I was drawing with an Overlay class not a Tool class.

It is standard practice in this community to provide a snippet to reproduce bugs, so other coders can test them on other platforms, with other CPUs and GPUs, etc.

If you file a report in the official bug tracker at GitHub, Thomas will ask for a reproducible code snippet. In fact, it is asked for in the report template. Without a snippet, either someone else would have to create one or the issue may get little traction.

Anyway, thank you for the “heads up” on this issue.

With SU 2020+ your tool can load and display texture images on the view, either 2D or 3D.

I can reproduce the problem, specific to SU2024.

I logged the issue in the API Issue tracker.

In SU2024

image

In SU2023

PS: I too prefer 4 spaces for a Tab.

2 Likes

By the way, same issue with Overlay.

in SU2024, view.draw2d(GL_POINTS, lst_points) draws in model space. In SU2023, it draws in 2D space.

[Fredo6] (Profile - Fredo6 - SketchUp Community)
I can reproduce the problem, specific to SU2024.
I logged the issue in the API Issue tracker.

Thank you very much Fredo! Talk less, work more! Real professional!!!

Thank you Fredo. I also saw it with your tool snippet.

But after manipulating the model to see the points, I got a BugSplat crash #71636.