I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a segmentation fault. I have no idea why this is.
Just to avoid the "just use C" comments, here is why I want to use Python:
There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.
Thanks for any help.
You may also want to consider using Pyglet instead of PyOpenGL. It's a ctypes-wrapper around the native OpenGL libs on the local platform, along with windowing support (should handle most of the stuff you want to use GLUT for.) The pyglet-users list is pretty active and very helpful.
Well, I don't know if these are the libs the original poster are using but I saw identical issues in a pet project I'm working on (Graphics Engine using C++ and Python) using PyOpenGL.
PyOpenGL didn't correctly pick up the rendering context if it was created after the python script had been loaded (I was loading the script first, then calling Python methods in it from my C++ code).
The problem doesn't appear if you initialize the display and create the OpenGL rendering context before loading the Python script.
What OpenGL library are you using? What windowing library? What version of Python?
Most likely cause I can think of is that your windowing library (SDL or whatever you're using) isn't initializing OpenGL before you start calling into it.
We have neither ideas about random segmentation faults. There is not enough information. What python libraries are you using for opengl? How do you use them? Can you show us your code? It's probably something trivial but my god -skill ends up to telling me just and only that.
Raytracer in python? I'd prefer just doing that in C with those structs. But then, I'm assuming you aren't going to do a realtime raytracer so that may be ok.
Perhaps you are calling an OpenGL function that requires an active OpenGL context, without having one? That shouldn't necessarily crash, but I guess it might. How to set up such a context depends on the platform, and it's been a while since I used GL from Python (and when I did, I also used GTK+ which complicates matters).
Scripts never cause segmentation faults.
But first see if your kernel and kmod video driver working property ...
Extension modules can cause "segmentation fault".
Related
I wish to use the wxPython class NotificationMessage in Windows. If doing so from a "TaskBarIcon" (i.e. a system tray app), there is an ugly glitch which is apparently resolved in the MSW port (via a preemptive function call to patch this special context). Here's some wxPython documentation indicating this:
https://docs.wxpython.org/wx.adv.NotificationMessage.html#wx.adv.NotificationMessage.UseTaskBarIcon
The problem I have, is the only instructions I see regarding how one employs the MSW port, is only seemingly in regards to the C++ wx library? https://docs.wxwidgets.org/trunk/page_port.html#page_port_wxmsw
I see nothing explaining how any of these platform specific ports are integrated into the wxPython library, as opposed to using them in C++ projects. Do I need to build wxPython from source, perhaps, with this "port" / flavor somehow? Or, would I need to include the dlls (or .so's) in my python project and make calls into them directly?
Overall this library, and it's documentation, is really excellent but I'm tripped up by this point.
I was able to solve my immediate problem by using the TaskBarIcon function ShowBalloon() instead. It does the exact same thing, without the glitch.
That said, I still would very much like to know what the answer is to the original question, before I encounter another platform specific situation like this, requiring one of these wx "ports"...
So, I have been wanting to make my own GUI library for Python 3. And I couldn't find anything anywhere on where to start. So I decided to ask the question here.
Goal:
Be able to make Python Libraries without using other libraries.
Edit:
So, If I was to make a Library in C for Python. How would I go about doing that.
Tkinter is a python wrapper around tcl/tk's GUI toolkit , similar to how PySide/PyQt and wxPython are wrappers around the Qt and Wx C++ GUI toolkits.
If you wanted to build your own from scratch you would have to make use of existing operating system APIs and/or use something cross platform like OpenGL. For a good example of the latter you can look into Kivy, which is built on OpenGL
Different operating systems have different API's for doing GUI's. So how you have to do it very much depends on the operating system. I think one of the reasons that Python uses Tkinter is because it was already ported to different operating systems.
GUI API's are typically provided as shared libraries, often written in or compatible with C.
If you want to use those from Python, you will have to write a Python wrapper for them. For example using ctypes. Doing that requires a significant understanding of (1) Python, (2) ctypes and (3) the GUI API in question. If more than one of these technologies is new to you, I would not recommend taking on such a project.
I googled and search stackoverflow before asking this question
Answers that I don't expect:
wxWidgets is the best Python GUIUse TkInter (BIM) for GUI development.
Q. How to make a GUI without using any module/library? i.e make a GUI from scratch. Modules like tkinter not allowed.
I've made several GUIs from scratch using SDL which is a low level drawing library. The advantage of doing that is that it will look exactly the same on any platform down to the pixel and you can get it to work on embedded systems. Full screen GUIs are really easy too. Disadvantages are that it is a lot of work.
In python the pygame library wraps SDL so you would use that, and in fact that is how I made the GUI for a lab instrument which had a large colour LCD screen. The controller ran linux, but not X-windows.
pygame is an extra library, yes, but I can't think of a way of making a GUI with only what python provides.
The easiest GUI to make without "module/library" is a web-based one. I.e. generate HTML with Javascript from your Python code, and let the Javascript interact via AJAX with your Python app. This can be implemented without too much effort with just the standard Python library (and some JS code, of course), or with modules that don't require "heavy" installation of platform-specific extensions.
I've been looking around for a nice lockscreen to use with my XFCE system, but it seems like there are any slim lock screens around. I'm currently using slock, but it's just a blank screen with absolutely no interface whatsoever.
I'm looking to code a lockscreen in Python. I looked at the source code for slock, and it seems like I have to interface with Xorg somehow.
Does anybody know anything about writing lockscreens?
If you want to go low-level, you can use python xcb bindings.
If you want to use higher level bindings, you may find this tutorial on writing a screen saver with Qt useful. Porting it to PyQt should be quite straightforward. I'm pretty sure similar resources exist for GTK.
I'm interested in playing around with OpenGL in Python. I've used OpenGL in C++ and Objective-C, but I don't have much experience in Python. I'm wondering if there's a good tutorial that works in Snow Leopard. I'd prefer to stay in 64-bit mode if possible, since I've heard 32-bit programs require loading a lot of extra 32-bit libraries.
I've already tried a PyOpenGL/wxPython tutorial. When I ran the code, it crashed with this message:
ImportError: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)
It looks like there's a bug in wxPython that prevents it from working on a 64-bit system.
I also looked at Pyglet, but they have a similar issue. They provide a work-around (setting Python to 32-bit mode), but it doesn't look like they're going to fix it.
Finally, I looked at PyGLUT, but I think it's only for Windows.
Are there any other libraries that would let me access OpenGL and draw on the screen? Again, I'd prefer to stay in 64-bit mode, but if nothing works, I'll switch to 32-bit and try wxPython or Pyglet again.
Edit: I've also tried PyGame. It depends on SDL which is broken in SL. I thought about trying to use Cocoa through PyObjc, but the Xcode Python application templates have been removed.
I've used PyOpenGL 3.0.0 quite successfully on Snow Leopard. It uses ctypes, so it should be making 64-bit calls if those libraries are available (and Snow Leopard's Python includes a 64-bit version). I haven't used the wxPython stuff with PyOpenGL so that's where you might be running into problems, but PyOpenGL also includes GLUT, which both run fine.
There's probably no good reason to avoid 32-bit mode. Unless your Python programs need to larger address space, of course.
You could try pygame. Pygame is a python wrapper around SDL. According to their website they have Max OS X binaries. Here is a simple example of using pygame with OpenGL. Once you are able to create the window and handle events most OpenGL programming is just like it would be in C or C++, but with some added python goodness. For OpenGL a great tutorial is NeHe.
Also when programing with OpenGL in python remember that Python datastructures can be rather slow when it comes to requirements for 3D graphics. PyGL developers for example recommend using ctypes for operations that concern graphics, since that way you can get enough performance for some complicated geometry with bareable FPS.