I've drawn a rectangle 4 line segmentsbut they're too thin. How can I change the thickness of each line? You can change the width of lines by calling glLineWidth. This is accomplished through pyglet like so:. If you require lines of varying thickness you'll have to call the function again with the new thickness before drawing each line. Otherwise, you can just set the thickness in your initialization and leave it be. Create points and draw a polygon between them to create the desired thickness.
I created a function on desmos which takes two points and finds new points to create the desired thickness T. I created a function to do this with each point. This may not be the most efficient way, but it works.
Python OpenGL Introduction
This function expects pyglet. Learn more. Ask Question. Asked 4 years, 11 months ago. Active 1 year, 7 months ago. Viewed 5k times.
Ericson Willians Ericson Willians 6, 9 9 gold badges 41 41 silver badges 82 82 bronze badges. Active Oldest Votes. This is accomplished through pyglet like so: pyglet. Josh Josh 3 3 silver badges 14 14 bronze badges. Late to the party, but you could just draw two pyglet.
Sean Christians Sean Christians 77 5 5 bronze badges.When I first began looking into OpenGL with Python, my main goal was to figure out how to make a rotating cube. I don't think I am alone, since this seems to be the pinnacle of understanding the basics of OpenGL. As such, I have compiled this first video to include everything from acquiring PythonPyOpenGLand PyGameto creating the necessary code to make a rotating cube. This first tutorial is quite long, but I wanted to go ahead and put everything into this video.
I did not, so this was a massive hurdle for me. Hopefully I can help you all learn it much faster than I did. So, the way OpenGL works is you just specify the objects within space. For a cube, for example, you specify the "corners. You may also see them referred to as a node singular or nodes plural.
Once you define the vertices, you can then do things with them. In this example, we want to draw lines between them. Defining the vertices is done with a simple list or tuple in Python. You can then pre-define some rules like what vertices make up a "surface" and between what vertices are the "edges," or lines that we want to have drawn between the vertices. Once you do that, then you're ready to write the OpenGL code. To do this, you have glBegin and glEnd statements that you call, and between these is where the OpenGL-specific code goes.
In the glBegin statement, you specify the "type" of code that you are about to pass. This basically notifies OpenGL how you want it to handle your statements. Just save that link to your bookmarks.
Super useful website. If you can type those statements and run them without any errors, then you are ready to proceed. If you are getting errors, something went wrong. Most of the time, the error is either you've downloaded the wrong Python version of PyGame or OpenGL, or the wrong bit version. So, if you are using 32 bit Python, you need to use 32 bit modules, and so on. Even if your operating system is a 64 bit OS, you may still find you're running a 32 bit version of Python.
I highly recommend using 64 bit Python if you can, 32 bit is limited to 2GB of ram, which is quite the limitation. If you have a 32 bit OS, then you cannot use 64 bit.As usual our goal is to do it in the easiest way possible, so everyone can understand it.
OpenGL is the way to go when it comes to throwing 3D graphics at our screen. The downside of Direct3D is that it only works on Windows, so if one day we would decide to make a game on Linux, we would have to re-learn another graphics library. To save us from that redundancy, we will just use OpenGL from the beginning.
Besides that, once understood OpenGL actually makes a lot of sense while being relatively simple. The download link on that website sends us over to this page. Now we just select the latest version and then we download the MS Windows Installer 32 bit :. If you don't get any errors, then don't worry about it. If we run it, the console pops up and asks us how to make a game. No errors occurred, everything worked fine. Note: those are the standard imports for OpenGL, just always use them and you will be fine.
So the first thing we want to do is create our window. We will need a window variable that holds our window id, a width and a height variable, and a few GLUT function calls.
If you never heard about GLUTit's just a little library that wraps all kinds of complicated OpenGL things into little functions like creating a window or drawing text. Please make sure to read the comments in order to understand what exactly happens when. The code above is the default construct to initialize OpenGL and create the window and start everything.
If we now run the program, we can already see our black window:. The most interesting thing about the initialization code is the glutDisplayFunc draw call. It tells OpenGL that it should call our draw function over and over again. If we want to draw something, we would do so in our draw function then.
Now you might noticed something similar in there: glutIdleFunc draw. This basically tells OpenGL to draw our things all the time, and not just every time the user interacts with the window. If in doubt, always use glutDisplayFunc and glutIdleFunc. Note: the draw function will be called about 60 times per second completely automatically. The concept is called callback. Let's talk about our draw function for a second.This is the second article from my OpenGL series.
It is time to actually draw something using OpenGL. First, let me mention that OpenGL is a low level API, this means that it has no support for drawing complex geometrical objects. The basic geometrical primitives that the core OpenGL profile provide to us are points, lines and triangles. For simplicity, we are going to use only two dimensional drawings in this article, but keep in mind that OpenGL allows us to represent three dimensional objects, more on this in a future article.
From a geometrical point of view, a triangle is completely defined by the position in space of his three corners or vertices. In OpenGL terminology, a vertex can be seen as a collection of attributes like position, color, texture coordinates etc ….
In the above figure we have four triangles and twelve vertices. If you look closely, you may notice that the points are written counterclockwise, this is important to keep in mind. By default, in OpenGL, a triangle with his vertices stored in counterclockwise order is said to be front facing. Why is this distinction important?
We can instruct OpenGL to render only one of the two faces of a triangle surface the front or the back ; the default is to render both faces. Another observation about the above array is that it stores only the xy coordinates for our triangles, this is because the z coordinate is zero for all twelve vertices.
So, how does OpenGL draws our triangles, now that we have their vertices in an array? The first step is to transfer the content of the above array in a Vertex Buffer Object. A VBO needs to be created, allocated and filled with data. We can also fill the VBO with data in the allocation step:. Line 3 from the above piece of code will create a handle for our VBOusing the glGenBuffers function.
Keep in mind that this function can create an array of handles if needed; for our particular case we have a single VBO so one handle will suffice.
Once a VBO is created, we need to bind it in order to modify or use it, this is what line 6 does with the glBindBuffer function. Once we have our data in a VBOwe can send it through the OpenGL pipeline - a number of steps and transformations through which our vertices will pass; the result is written in a framebuffer.It really depends on the context that you are trying to draw the line in. Are you trying to draw in 2D or 3D?
Do you want this stored in a Texture or as a file on disk? If you wanted to capture the data in a Texture you could try doing a render-to-texture operation and using your BGL code to draw into that texture.
If you use PIL then you can create images directly in memory and write them to disk.
Getting that image data into a Blender texture would require some extra work. Please note that the original PIL project stopped being maintained. What I want is to draw in the render result and save the image. Do you know any website or article to give some advice about this?
I do not know if this is the best way, but you can change each pixel of an image: for example, to change the first pixel in the lower left corner of an imagewe can type:. In python I have something like this: bgl. I want to draw a line, and then save the image. I do not know if this is the best way, but you can change each pixel of an image: for example, to change the first pixel in the lower left corner of an imagewe can type: bpy.
I would think that the op is looking for a way to make his measureit addon render able.
Subscribe to RSS
Buffer bgl.GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
We use optional third-party analytics cookies to understand how you use GitHub. Learn more. You can always update your selection by clicking Cookie Preferences at the bottom of the page. For more information, see our Privacy Statement. We use essential cookies to perform essential website functions, e. We use analytics cookies to understand how you use our websites so we can make them better, e. Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up. No definitions found in this file. Latest commit e Mar 14, History. Add more samples: cube, robot, projection, rotate, circle, light, color. Raw Blame. Init glfw. OpenWindow widthheight8880240glfw. SetWindowTitle "glfw circle" glfw.
SwapBuffers if glfw. GetKey glfw.Python programming for beginners: What can you do with Python?
Terminate Copy lines Copy permalink View git blame Reference in new issue. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Accept Reject.A question I am frequently asked is how to avoid paying for the additional weight of the container. Stores have various methods for deducting the container weight. At Whole Foods, for example, I take my containers to the customer service desk to have them weighed before filling.
That weight is then deducted from the total weight of the item at the checkout counter.
At Berkeley Bowl, empty containers are weighed at the Bulk Counter and then weighed again at the same counter when full before checking out.
At Rainbow Grocery, customers weigh their own containers. And all the cotton bags that I use are printed with the tare weight on their tags. Concerned about cross contamination for people with allergies. Check out my post on avoiding gluten while still living plastic-free. Even if you live in an area that does not have bulk food stores, you can still buy non-perishable goods in large size packages, which will decrease the amount of plastic used overall. What are we worried about.
Or is it that the produce will get dirty. At the grocery store, I put most produce directly into my cart and then into my reusable bag. If you do feel you want a separate bag for produce, cloth options are available. Some alternatives are Ambatalia, ECOBAGS, ChicoBag produce bags, or handmade bags from Etsy sellers. Check out this video of a woman who can make five reusable bags from one T-shirt.
OpenGL 101: Drawing primitives - points, lines and triangles
Wondering how to store your produce without plastic once you get it home. Check out this extensive list of ways to buy and store produce without plastic, or specifically buying and storing loose lettuce and leafy greens. Read more about farmers markets going plastic-free. I buy Spectrum vinegar which comes in a glass bottle.
Only the cap is plastic. It scours well and leaves dishes feeling squeaky clean. For really tough baked-on messes, I use a Chore Boy copper scrubber, which comes in a cardboard box with no plastic. Coconut coir brushesare great for cleaning water bottles and scrubbing dirty dishes. Skoy cloths are made from cotton and cellulose, work like a cloth, absorb like a sponge, and can take the place of 15 rolls of paper towels.