# SU2024 API Problem with view.draw2d GL\_POINTS

**URL:** <https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619>\
**Category:** Ruby API\
**Tags:** sketchup, bug, ruby\
**Created:** [May 24, 2024, 11:16am UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619 "2024-05-24T11:16:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![borisovsfam](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@borisovsfam](https://forums.sketchup.com/u/borisovsfam)\
**Post date:** [May 24, 2024, 11:16am UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/1 "2024-05-24T11:16:37Z")

</div>

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:

```auto
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:

```auto
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:

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/9/c/9c6cda186133b3119d5487c99a67bf04bd69ce0e.png)

Result in SketchUp of any other version:

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/e/b/eb0778f5f2509002c10f024b35a36e554b9a411e.png)

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.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 24, 2024, 7:58pm UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/2 "2024-05-24T19:58:29Z")

</div>

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 …

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

```

… and …

```ruby
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.)

---

<div class="post-metadata">

**Author:** ![borisovsfam](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@borisovsfam](https://forums.sketchup.com/u/borisovsfam)\
**Post date:** [May 25, 2024, 6:22am UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/3 "2024-05-25T06:22:20Z")

</div>

> 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](https://ruby.sketchup.com/Sketchup/View.html#draw2d-instance_method)

> 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!!

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 25, 2024, 8:52am UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/4 "2024-05-25T08:52:50Z")

</div>

> [@borisovsfam](#):
>
> 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)

Except that I did not see this in 2024 when I was using `draw2d` with `GL_POINTS`.  
**But** I was drawing with an [`Overlay`](https://ruby.sketchup.com/Sketchup/Overlay.html) class **not** a [`Tool`](https://ruby.sketchup.com/Sketchup/Tool.html) 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](https://github.com/SketchUp/api-issue-tracker/issues?q=is%3Aopen+is%3Aissue+label%3A%22Ruby+API%22+label%3ASketchUp), 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.

> [@borisovsfam](#):
>
> I think I’ll also have to reconsider the way I display these pictures.

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

---

<div class="post-metadata">

**Author:** ![Fredo6](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fredo6/32/77024_2.png) [@Fredo6](https://forums.sketchup.com/u/Fredo6)\
**Post date:** [May 25, 2024, 3:03pm UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/5 "2024-05-25T15:03:27Z")

</div>

I can reproduce the problem, specific to SU2024.

I logged the issue in the [API Issue tracker](https://github.com/SketchUp/api-issue-tracker/issues/975).

**In SU2024**

![image](https://global.discourse-cdn.com/sketchup/original/3X/f/e/feb190e45ef42a138eb57d953fe65d2e3b3c3dc4.png)

**In SU2023**

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/c/5/c5a7f27bc7d980e7a088647aa972a1cf7e9e16c4.png)

PS: I too prefer 4 spaces for a Tab.

---

<div class="post-metadata">

**Author:** ![Fredo6](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fredo6/32/77024_2.png) [@Fredo6](https://forums.sketchup.com/u/Fredo6)\
**Post date:** [May 25, 2024, 3:14pm UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/6 "2024-05-25T15:14:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![borisovsfam](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@borisovsfam](https://forums.sketchup.com/u/borisovsfam)\
**Post date:** [May 25, 2024, 3:53pm UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/7 "2024-05-25T15:53:41Z")

</div>

> [Fredo6] ([Profile - Fredo6 - SketchUp Community](https://forums.sketchup.com/u/Fredo6))  
> I can reproduce the problem, specific to SU2024.  
> I logged the issue in the [API Issue tracker](https://github.com/SketchUp/api-issue-tracker/issues/975).

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 25, 2024, 5:40pm UTC](https://forums.sketchup.com/t/su2024-api-problem-with-view-draw2d-gl-points/274619/8 "2024-05-25T17:40:30Z")

</div>

> [@Fredo6](#):
>
> I can reproduce the problem, specific to SU2024.
> 
> I logged the issue in the [API Issue tracker](https://github.com/SketchUp/api-issue-tracker/issues/975).

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.
