前田/日誌/2009-12-21
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[前田/日誌]]
***メモ [#td0bb013]
-試しに以下のサイトのOpenGL講座の演習問題をHaskellに移植してみた。~
http://verygood.aid.design.kyushu-u.ac.jp/opengl/index.html
--C言語ソースコード
#include <GL/gl.h>
#include <GL/glut.h>
//--初期化処理------------------------------------------------------------------
void myinit(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //背景色の設定(R,G,B,ALPHA) 0.0-1.0の範囲で
}
//--描画内容--------------------------------------------------------------------
void display(void)
{
int i=0;
glClear(GL_COLOR_BUFFER_BIT); //画面全体を背景色で塗りつぶす
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //単位行列を行列スタックに読み込む
glColor3f(1.0f, 1.0f, 1.0f); //頂点カラーの指定( R, G, B すべてが1.0fなら白)
for(i=0;i<10;i++) {
glBegin(GL_LINES);
glVertex2f( -0.5f, 0.5f-0.1f*i);
glVertex2f( -0.5f+0.1f*i, -0.5f);
glVertex2f( -0.5f+0.1f*i, -0.5f);
glVertex2f( 0.5f, -0.5f+0.1f*i);
glVertex2f( 0.5f, -0.5f+0.1f*i);
glVertex2f( 0.5f-0.1f*i, 0.5f);
glVertex2f( 0.5f-0.1f*i, 0.5f);
glVertex2f( -0.5f, 0.5f-0.1f*i);
glEnd();
}
glFlush(); //OpenGLで実際に描画を行う
}
//--再描画----------------------------------------------------------------------
void myReshape(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h); //ウィンドウ全体をビューポートにする
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //単位行列を行列スタックに読み込む
glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
}
//--メイン関数------------------------------------------------------------------
int main(int argc, char **argv)
{
glutInitWindowPosition(100, 100); //(図形が描画される)ウィンドウ位置の設定
glutInitWindowSize(600, 600); //(図形が描画される)ウィンドウサイズの設定
glutInit(&argc, argv); //環境の初期化
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE); //表示モードの設定
glutCreateWindow("line"); //ウィンドウを開く
glutDisplayFunc(display); //図形表示関数の指定
myinit();
glutReshapeFunc(myReshape); //座標軸・ビューポート設定関数の指定
glutMainLoop(); //無限ループ
return 0;
}
--Haskell版
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
createPosL :: [(GLfloat,GLfloat)]
createPosL = concat $ map ( \x->[(-0.5,0.5-0.1*x),(-0.5+0.1*x,-0.5)] ) [0..9]
createPosB :: [(GLfloat,GLfloat)]
createPosB = concat $ map ( \x->[(-0.5+0.1*x,-0.5),(0.5,-0.5+0.1*x)] ) [0..9]
createPosR :: [(GLfloat,GLfloat)]
createPosR = concat $ map ( \x->[(0.5,-0.5+0.1*x),(0.5-0.1*x,0.5)] ) [0..9]
createPosT :: [(GLfloat,GLfloat)]
createPosT = concat $ map ( \x->[(0.5-0.1*x,0.5),(-0.5,0.5-0.1*x)] ) [0..9]
main = do
(progname, _) <- getArgsAndInitialize
initialWindowSize $= Size 600 600
initialWindowPosition $= Position 100 100
initialDisplayMode $= [RGBAMode,SingleBuffered]
createWindow "line"
displayCallback $= display
myInit
reshapeCallback $= Just reshape
mainLoop
myInit = do clearColor $= Color4 0.0 0.0 0.0 0.0
display = do
clear [ColorBuffer]
matrixMode $= Modelview 0
loadIdentity
color $ (Color3 (1.0::GLfloat) 1.0 1.0)
renderPrimitive Lines $ do
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosL
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosB
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosR
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosT
flush
reshape s@(Size w h) = do
viewport $= (Position 0 0, s)
matrixMode $= Projection
loadIdentity
ortho (-1.0) (1.0) (-1.0) (1.0) (-1.0) (1.0)
----
#comment
終了行:
[[前田/日誌]]
***メモ [#td0bb013]
-試しに以下のサイトのOpenGL講座の演習問題をHaskellに移植してみた。~
http://verygood.aid.design.kyushu-u.ac.jp/opengl/index.html
--C言語ソースコード
#include <GL/gl.h>
#include <GL/glut.h>
//--初期化処理------------------------------------------------------------------
void myinit(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //背景色の設定(R,G,B,ALPHA) 0.0-1.0の範囲で
}
//--描画内容--------------------------------------------------------------------
void display(void)
{
int i=0;
glClear(GL_COLOR_BUFFER_BIT); //画面全体を背景色で塗りつぶす
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //単位行列を行列スタックに読み込む
glColor3f(1.0f, 1.0f, 1.0f); //頂点カラーの指定( R, G, B すべてが1.0fなら白)
for(i=0;i<10;i++) {
glBegin(GL_LINES);
glVertex2f( -0.5f, 0.5f-0.1f*i);
glVertex2f( -0.5f+0.1f*i, -0.5f);
glVertex2f( -0.5f+0.1f*i, -0.5f);
glVertex2f( 0.5f, -0.5f+0.1f*i);
glVertex2f( 0.5f, -0.5f+0.1f*i);
glVertex2f( 0.5f-0.1f*i, 0.5f);
glVertex2f( 0.5f-0.1f*i, 0.5f);
glVertex2f( -0.5f, 0.5f-0.1f*i);
glEnd();
}
glFlush(); //OpenGLで実際に描画を行う
}
//--再描画----------------------------------------------------------------------
void myReshape(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h); //ウィンドウ全体をビューポートにする
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //単位行列を行列スタックに読み込む
glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
}
//--メイン関数------------------------------------------------------------------
int main(int argc, char **argv)
{
glutInitWindowPosition(100, 100); //(図形が描画される)ウィンドウ位置の設定
glutInitWindowSize(600, 600); //(図形が描画される)ウィンドウサイズの設定
glutInit(&argc, argv); //環境の初期化
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE); //表示モードの設定
glutCreateWindow("line"); //ウィンドウを開く
glutDisplayFunc(display); //図形表示関数の指定
myinit();
glutReshapeFunc(myReshape); //座標軸・ビューポート設定関数の指定
glutMainLoop(); //無限ループ
return 0;
}
--Haskell版
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
createPosL :: [(GLfloat,GLfloat)]
createPosL = concat $ map ( \x->[(-0.5,0.5-0.1*x),(-0.5+0.1*x,-0.5)] ) [0..9]
createPosB :: [(GLfloat,GLfloat)]
createPosB = concat $ map ( \x->[(-0.5+0.1*x,-0.5),(0.5,-0.5+0.1*x)] ) [0..9]
createPosR :: [(GLfloat,GLfloat)]
createPosR = concat $ map ( \x->[(0.5,-0.5+0.1*x),(0.5-0.1*x,0.5)] ) [0..9]
createPosT :: [(GLfloat,GLfloat)]
createPosT = concat $ map ( \x->[(0.5-0.1*x,0.5),(-0.5,0.5-0.1*x)] ) [0..9]
main = do
(progname, _) <- getArgsAndInitialize
initialWindowSize $= Size 600 600
initialWindowPosition $= Position 100 100
initialDisplayMode $= [RGBAMode,SingleBuffered]
createWindow "line"
displayCallback $= display
myInit
reshapeCallback $= Just reshape
mainLoop
myInit = do clearColor $= Color4 0.0 0.0 0.0 0.0
display = do
clear [ColorBuffer]
matrixMode $= Modelview 0
loadIdentity
color $ (Color3 (1.0::GLfloat) 1.0 1.0)
renderPrimitive Lines $ do
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosL
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosB
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosR
mapM_ (\(x,y)->vertex $ (Vertex2 x (y::GLfloat))) createPosT
flush
reshape s@(Size w h) = do
viewport $= (Position 0 0, s)
matrixMode $= Projection
loadIdentity
ortho (-1.0) (1.0) (-1.0) (1.0) (-1.0) (1.0)
----
#comment
ページ名: