Computer Graphics -practical- Lecture 6

advertisement
Computer Graphics
-practicalLecture 6
(visual c++) open gl library
To use open GL with VC++ we add these files:1)Glut.h
C:\program files\ Microsoft visual
studio\vc98\include\GL
2)Glut32.dll
C:\windows\system
3)Glut32.lib
C:\program files\ Microsoft visual studio\ v098\lib
After include these files start the visual C++ program.
Getting Started
• You’ll be using VC++ 2010 environment (Download)
• You should already have OpenGL libraries:
glut32.dll
glut32.lib
glut.h
GLUT files from the web
(www.xmission.com/~nate/glut.html)
• To draw the main shape (line , triangle, dot ……)the
screen is divided to :
• In open GL we need three functions to draw the main
shapes :
• (program steps )
• Open GL program structure:
Header files
Function to determine the type of the shape
Function to determine the points of the shape
Function to end of the points of the shape
• Function that use to determine the type of the
shapes:
• glBegin(NAME);
Name
DESCREPTION
GL_POINTS
Draw point
GL_LINES
Draw line
GL_TRIANGLES
To Draw triangle0lo
GL_POLYGON
To Draw polygon
• Function that use to determine the points of the
shapes:• two dimensional or 3 dimensional
glVertex2F(X.Y);
glVertex3F(X.Y);
• *Function to end the points of the shape
glEnd();
•
•
•
•
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
• Write the VC++ program using open GL library
to draw point.
•
•
•
•
•
•
Open the VC++ to write the code
Start --- visual C++2010 ----new
Project :win 32 application
Files: C++ source code
Then write the program name
Name: dpoint
#include <windows.h>
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(8);
glBegin(GL_POINTS);
glVertex2f(0.0,0.0);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("draw point");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
#include <windows.h>
#include<glut.h> //header file, define the opengl
library
void display() //Function to display
{
glClear(GL_COLOR_BUFFER_BIT); /* this function
use to clear the buffer before draw any shape */
glPointSize(8);
glBegin(GL_POINTS); /* function to declare the
type of the shape “here to draw point” */
glVertex2f(0.0,0.0); /* function to determine
the place of the shape on the screen */
glEnd(); /*used to determine the end of the
shape point */
glFlush(); //function to view the shape
}
// For user interface
int main(int argc, char **argv)
{
glutInit(&argc,argv);
/* Open gl utility toolkit: use to call glut
function to view window */
glutCreateWindow("draw point"); /* name of the
window (any name) */
glutDisplayFunc(display); /* call the function
display */
glutMainLoop(); /* function for looping the
program, then all ways come at the end (Display the
window until you close) */
return 0;
}
Download