OpenGL:
I'm using OpenGL and QT creator in Ubuntu environment. I will constantly make short notes about problems and solutions in programming.
Adding OpenGL Library
To add external library, right click on the project or .pro file then click >>Add new library >>External library >>Browse "usr/lib/libGLEW.so"
Or edit the *.pro file by adding "LIBS += -L$$PWD/../../../../../../usr/lib/ -lglut -lGLEW"
A good OpenGL tutorial can be found here or here.
Create a simple project
1. Firstly, open QT Creator and create a empty project.2. Add libraries (see above). After adding two libraries you can see the "-lglut -lGLEW" in the *.pro file.
3. Add the main source file (main.cpp)
4. Finally build and execute the project.
------------------------------------main.cpp----------------------------------------
#include <GL/glut.h> void display(){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush(); } void init(){ glClearColor (0.0, 0.0, 0.0, 0.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } int main(int argc, char** argv){ glutInit(&argc,argv); glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMainLoop(); }
--------------------------------------------------------------------------------------
Another useful material click here.
No comments:
Post a Comment