Saturday, 18 August 2012

OpenGL beginning guide(glui)

1. Download the latest version of glui sourse code. (mine was glui-2.36)
2. Extract the zip file, and open the src/msvc/glui.sln file in vc++
3. Select the _glui library and build the library.
4. After building the library, the lib file (glui32d.lib), glui32d.lib – ‘d’ for debug, will be stored in the msvc\lib directory.
5. Put the glui32d.lib file into C:\Program Files\Microsoft Visual Studio 10.0\VC\lib directory and rename to glui32.lib
6. Put the glui.h file into C:\Program Files\Microsoft Visual Studio 10.0\VC\include directory.
7. Create new project and try to compile. That's all.

Note : For VS 2010 users, the error below may be generated when compiling the library.
 
1error C2252: an explicit instantiation of a template can only occur at namespace scope

Try this,
  1. Cut the corresponding block code and paste outside the class GLUIAPI GLUI_CommandLine definition
    1#ifdef _MSC_VER
    2// Explicit template instantiation needed for dll
    3template class GLUIAPI std::allocator<GLUI_String>;
    4template class GLUIAPI std::vector<GLUI_String,
    5std::allocator<GLUI_String> >;
    6#endif
  2. Put #include <iterator> after #include <cstdlib>
    1#include <cstdlib>
    2#include <iterator>

  3. Build it as usual

Wednesday, 8 August 2012

A Sample using GLUT

This is a sample of a moving cube:

#include <iostream>
#include <GL/glut.h>
#include <cstdlib>

using namespace std;
static GLfloat spin=0.0;
void init(void){
 glClearColor(0.0,0.0,0.0,0.0);
 glShadeModel(GL_FLAT);
}
void display(void){
 glClear(GL_COLOR_BUFFER_BIT);
 glPushMatrix();
 glRotatef(spin,0.0,0.0,1.0);
 glColor3f(1.0,1.0,1.0);
 glRectf(-25.0,-25.0,25.0,25.0);
 glPopMatrix();
 glutSwapBuffers();
}
void spinDisplay(void){
 spin=spin+1.5;
 if(spin>360.0)
  spin=spin-360.0;
 glutPostRedisplay();
}
void reshape(int w, int h){
 glViewport(0,0,(GLsizei)w,(GLsizei)h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
}
void mouse(int button, int state, int x, int y){
 switch(button){
 case GLUT_LEFT_BUTTON:
  if (state==GLUT_DOWN)
   glutIdleFunc(spinDisplay);
  break;
 case GLUT_RIGHT_BUTTON:
  if (state==GLUT_DOWN)
   glutIdleFunc(NULL);
  break;
 default:
  break;
 }
}
int main(int argc, char** argv){
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
 glutInitWindowSize(250,250);
 glutInitWindowPosition(100,100);
 glutCreateWindow(argv[0]);
 init();
 glutDisplayFunc(display);
 glutReshapeFunc(reshape);
 glutMouseFunc(mouse);
 glutMainLoop();
 return 0;
}

Thursday, 2 August 2012

OpenGL Beginning Guide(glut)

1. Download C++ Express at
 http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

2. Install C++ Express.

3. Download OpenGL files at http://www.opengl.org/resources/libraries/glut/

4. Copy files as follows:
    glut.h/glu.h/gl.h : C:\Program Files\Microsoft Visual Studio [version]\VC[version]\include\GL
    glut32.lib : C:\Program Files\Microsoft Visual Studio [version]\VC[version]\lib
    glut32.dll : C:\Windows\System32;   C:\Program Files\Microsoft Visual Studio [version]\VC[version]\bin

5. Open C++ Express and create your own project.

references:
http://cacs.usc.edu/education/cs596/OGL_Setup.pdf
http://www.mbsoftworks.sk/index.php?page=tutorials&series=1