OpenGL de プログラミング - ドラッグ処理
現在地 >> メニュー >> サンプルコード::OpenGL >> ドラッグ処理

次 >> ドラッグ処理2

問題


ウィンドウを作成し、ドラッグ処理を行ってる間、
何かをコマンドプロンプトに表示せよ。

答え


#include <cstdio>
#include <GL/glut.h>

void display();
void MouseDrug(int x, int y);

using namespace std;


inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA);
}


inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutMotionFunc(MouseDrug);
}

inline void MY_INIT()
{
glClearColor(0.0, 1.0, 0.0, 1.0);
}


int main(int argc, char **argv)
{
glutInit(&argc,argv);
GLUT_INIT();

glutCreateWindow("window name");

GLUT_CALL_FUNC();
MY_INIT();

glutMainLoop();

return 0;
}

/********[ここからコールバック]****************************************/
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();

}

void MouseDrug(int x, int y)
{
printf("X = %d : Y = %d\n" , x , y);

}

メモ


どのボタン反応する。
特定のボタンのドラッグ処理には、フラグが必要。