2 steps below need to be taken care of:
Step 1:
Step 2:
Open Visual Studio 2008:
File -> New Project -> Visual C++ -> General -> Empty Project
Right Click on Source Files -> New Item... -> C++ file (.cpp)
Write code below:
[Code]
// @Author: Vic
// @Date: 9/21/2012 2:38AM
#include "stdafx.h"
#include
void init(void)
{
glClearColor(1.0 , 1.0 ,1.0 , 0.0); // Set display-window color to white
glMatrixMode(GL_PROJECTION); // Set projection parameter
gluOrtho2D(0.0,200.0,0.0,150.0); //
}
void lineSegment(void){
glClear(GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f(1.0, 0.0, 0.0); // Set line segment color to red (R,G,B)
glBegin(GL_LINES);
glVertex2i(180,15); // Specify line-segment geometry x1,y1 ; x2,y2
glVertex2i(10,145);
glEnd();
glFlush(); // Profess all OpenGL routines as quickly as possible.
}
void main(int argc, char** argv)
{
glutInit(&argc, argv); // Initialize GLUT dll that we copy it in c:\windows\System32
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowPosition (50,100); // set top-left display window position
glutInitWindowSize(400,300); // set display window width / height
glutCreateWindow("An Example OpenGL Program"); // Create display window title.
init(); // Execute initialization procedure
glutDisplayFunc(lineSegment); // Send graphics to display window. our function above main
glutMainLoop(); // Display everything and wait.
}
[/Code]
Run it:
Output:
Congratulation you have run your first C++ OpenGL.
Vic,
Correction for the header files I have made a mistake while commenting and accidentally delete the Glut header file declaration you would find the correction below:
#include "stdafx.h"
#include "GL/glut.h"
0 comments:
Post a Comment
Thanks for commenting...