第2回です。 どうも、ゆるキャン△を観たからではないですが、唐突にゴールデンウィークにキャンプを企画したyosiです。 今回はまた下準備ですが、OpenGLのバージョン指定やウィンドウの表示をしていきます。 OpenGLのバージョンは非常にややこしいのですが、最近のバージョンはかなりややこしさが軽減されていて助かります。 まずはOpenGLのバージョンを指定 glfw.init() window = glfw.create_window(640, 480, 'Hello World', None, None) glfw.make_context_current(window) glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0) glfw.window_
Python2のコードを3で動かしたい。 2to3 http://diveintopython3-ja.rdy.jp/porting-code-to-python-3-with-2to3.html python3にはPython2コードをPython3コードに変換するツール2to3が付属しているらしい。 PyOpenGL-Demo Python3.6.1でインストールしたが、ソースコードがPython2用っぽい。 venvでgame仮想環境を作成し、インストール。以下のパスを見てみた。 /.../game/lib/python3.6/site-packages/PyOpenGL-Demo/NeHe配下にlesson1.pyのようなコードがある。 2→3 lesson1.pyファイルをコピーする(上書きされたら困るから) $ 2to3 lesson1.py -w $ 2to3 lesson1
PyOpenGLでテクスチャを表示する。 import sys from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from PIL import Image def load_texture(): img = Image.open("sample1.png") w, h = img.size glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.tobytes()) def display(): glClear(GL_COLOR_BUFFER_BIT) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND)
glutMainLoopは仕様上、実行されたが最後、呼び出し元に戻ることはできない。 GLUTでの終了時のメモリの開放はOSに任せている。ただ、プロセス中に一時グラフィック表示をする場合、glutMainLoopから抜ける必要がある。そのために使う関数はfreeGLUTに用意されている。freeglutの使用はヘッダファイルのインクルードが必要である。 #include <GL/freeglut.h> glutSetOption glutMainLoop()に入る前に、glutSetOptionにて以下を指定する。 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); … … glutMainLoop(); glutMainLoop()から抜ける場合はglutLeaveMainLoop()を
「PyOpenGLのインストールができない!!」 「PyOpenGLが動かない・・・」 このような場合は、この記事をご覧ください。 PyOpenGLが動くまでを説明します。 本記事の内容 PyOpenGLとは?PyOpenGLのシステム要件PyOpenGLのインストールPyOpenGLの動作確認 それでは、上記に沿って解説していきます。 PyOpenGLとは? PyOpenGL公式サイト http://pyopengl.sourceforge.net/ PyOpenGLは、OpenGLとその関連APIに対するPythonバインディングです。 プログラムからOpenGLを気軽に触る場合には、最適な選択肢となります。 しかし、PyOpenGLを動かすまでがちょっと面倒です。 公式サイトを見ればわかりますが、決して親切とは言えません。 また、Googleで検索しても情報が錯綜しています。 今時の
#!/usr/bin/python # coding: utf-8 from OpenGL.GL import * from OpenGL.GLUT import * def draw(): # OpenGLバッファのクリア glClearColor(0.0, 0.5, 0.5, 0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # OpenGL描画実行 glFlush() # glutダブルバッファ交換 glutSwapBuffers() def setup(): glutInit(sys.argv) # RGBAモード、ダブルバッファリング有効、Zバッファ有効で初期化 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(64
pygameとopenglを使ったひな形的なコードです。 ・png画像表示 ・日本語テキスト表示 ・pngは透過色指定で透過(抜け色) ・画像/フォントを行列により回転 ・アルファブレンディング を行っています。したがって、pygameとpyopenglモジュールが必要です。 また、コードと同じフォルダに、以下のファイルを置いてください。 ・test.png (表示用。テキトーな画像でOK。縦横サイズともに2の倍数。256*256ぐらいがおすすめ。) ・ipag.ttf (IPAフォント。どっかでダウンロードしてきてください。) #!/usr/bin/env python # -*- coding: utf-8 -*- import os,sys import pygame from pygame.locals import * from OpenGL.GL import * from O
The following uses ctypes to get to the OpenGL 1.5/2.0 functions not exported by PyOpenGL. See GLSL_ARB_Example for an implementation using the OpenGL ARB extensions. from ctypes import * import sys import pygame from pygame.locals import * try: # For OpenGL-ctypes from OpenGL import platform gl = platform.OpenGL except ImportError: try: # For PyOpenGL gl = cdll.LoadLibrary('libGL.so') except OSEr
The OpenGL Utility Toolkit (GLUT), originally written by Mark Kilgard, ported to Win32 (Windows 95,98,Me,NT,2000,XP) by Nate Robins. For more information check out the README-win32.txt provided in the distribution for installation instructions, and Win32 specific information.. The latest version of the library is 3.7.6 (Nov 8, 2001)! glut-3.7.6-bin.zip (117 KB) GLUT for Win32 dll, lib and header f
すんなりとはいかなかった。 インストール http://www.xucker.jpn.org/pc/pythonexec.html まず、こちらを参考にvcランタイムの問題をクリアする。 http://d.hatena.ne.jp/AMENOHI/20090202/1233575464 exeを実行するとpyOpenGLのエラーがでる。 $ ./dist/gui.exe Traceback (most recent call last): File "gui.py", line 9, in <module> from OpenGL.GL import * File "OpenGL\GL\__init__.pyc", line 2, in <module> File "OpenGL\raw\GL\__init__.pyc", line 6, in <module> File "OpenGL\
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く