• 검색 결과가 없습니다.

Computer Graphics

N/A
N/A
Protected

Academic year: 2023

Share "Computer Graphics"

Copied!
34
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Computer Graphics

Lee Byung-Gook

(2)

OpenGL

• Most Widely Adopted Graphics Standard

• High Visual Quality and Performance

• Industry standard, Reliable and portable

• Stable, Easy to use and Well-documented

(3)

OpenGL software libraries

(4)

Software libraries

• OpenGL : provides most of the graphics functionality

• GLU : provides support for some additional

operations and primitive types, and is implemented using OpenGL function calls

• glut : designed specifically to be used with OpenGL and it takes care of things like opening windows, redraw events, and keyboard and mouse input. It effectively hides all the windowing system

dependencies for OpenGL

(5)

Installing OpenGL for Windows

• bundled with Win98, Win95, WinNT or download** it

• look for dynamically-linked libraries (dlls):

– C:\Winnt\system32\Opengl32.dll on Windows NT – C:\Windows\system\Opengl32.dll on Windows 95

• look for header files, e.g., for Visual C++:

– C:\Program Files\Microsoft Visual Studio\VC98\include\gl\*.h

(6)

Installing glut for Windows

• http://www.opengl.org/resources/libraries/glut/glutdlls 37beta.zip

• glut.h

– C:\Program Files\Microsoft Visual Studio\VC98\include\gl\glut.h

• glut32.lib

– C:\Program Files\Microsoft Visual Studio\VC98\lib\glut32.lib

• glut32.dll

– C:\Windows\system32\glut32.dll on Windows 95, 98 – C:\WINNT\system32\glut32.dll on Windows 2000, NT

(7)

Compiling with Visual C++

• Start Visual C++

• Choose File  new, then from the Projects tab selec t Win32 Console Application

• Assign the project a name (`lab00' for example), and c hoose a directory where the project files will be stored

• Choose File  new, then from the Files tab select C ++ Source File

• Assign the file a name, ‘lab00' for example. The .cpp e xtension will be added for you.

• Fill in the file lab00.cpp

(8)

lab00.cpp

// lab00.cpp, Computer Graphics, lbg@dongseo.ac.kr

#include <GL/glut.h>

void myDisplay(void) {

glClearColor (.75, .75, .75, 0.0);

glMatrixMode(GL_PROJECTION);

glOrtho(0, 500, 0, 500, -1, 1);

glMatrixMode(GL_MODELVIEW);

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.60, .40, .70);

glBegin(GL_POLYGON);

glVertex2i(450, 250);

glVertex2i(412, 367);

glVertex2i(312, 440);

glVertex2i(188, 440);

glVertex2i(88, 368);

glVertex2i(50, 250);

glVertex2i(88, 132);

glVertex2i(188, 60);

glVertex2i(312, 60);

glVertex2i(412, 132);

glEnd();

glFlush();

}

void main(int argc, char** argv) {

glutInit(&argc,argv);

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(0,0);

glutCreateWindow("lab00");

glutDisplayFunc(myDisplay);

glutMainLoop();

}

(9)

Compiling with Visual C++

• Choose Project  Settings and select the C/C++

panel. Enable Generate browse info.

• Select the Link panel. At the beginning (or anywhere) of the Object/library modules entry, add the

libraries opengl32.lib and glut32.lib. Accept all the

project setting changes by choosing OK.

(10)

Compiling with Visual C++

• Choose Build  Build lab00.exe, or simply hit the F7 key in order to compile and link.

• A successful compilation would have produced the following output in your 'build' window:

• ---Configuration: lab00 - Win32 Debug--- Compiling...

lab00.cpp

Linking... lab00.exe - 0 error(s), 0 warning(s)

(11)

Compiling with Visual C++

• If there are errors, hitting F4 will take you to the location of the first error message in the code, and thereafter always take you to the next error

message. Or, one can double click on any error message to jump to the relevant source code.

• Once the code has successfully compiled and linked, Build-Execute or Ctrl-F5 will run the code, as will

double-clicking on the test.exe icon (found in the

Debug directory) from a file browsing window.

(12)

Basic drawing

• OpenGL is a "state" machine : Once it is in a state, it stays in th at state until the state is changed.

• Basic commands

glClearColor(red, green, blue, 0.0);

// sets background color

glClear(GL_COLOR_BUFFER_BIT);

// clears the window to the background color glColor3f(red, green, blue);

// values between 0.0 (no color) & 1.0 (full color) glBegin(*);

// determines how vertices are interpreted

(13)

Basic drawing

glVertex2i(412, 367);

glVertex2i(312, 440);

glVertex2i(188, 440);

glVertex2i(88, 368);

glVertex2i(50, 250);

glVertex2i(88, 132);

glVertex2i(188, 60);

glVertex2i(312, 60);

glVertex2i(412, 132);

glEnd();

// clears the state initiated by

(14)

Colors

{1.0f, 0.0f, 0.0f} //red {0.0f, 1.0f, 0.0f} //green {0.0f, 0.0f, 1.0f} //blue {1.0f, 1.0f, 0.0f} //yellow {1.0f, 0.0f, 1.0f} //magenta {0.0f, 1.0f, 1.0f} //cyan {1.0f, 1.0f, 1.0f} //white {.25f, .25f, .25f} //dark gray {.75f, .75f, .75f} //light gray {.60f, .40f, .12f} //brown

{.60f, .40f, .70f} //barney purple {.98f, .625f, .12f} //pumpkin orange {.98f, .04f, .70f} //pastel pink

(15)

Drawing primitives

• OpenGL supports several basic primitive types, including points, lines, quadrilaterals, and general polygons. All of these primitive s are specified using a sequence of vertices.

• glBegin and glEnd delimit the vertices that define a primitive or a group of like primitives.

• GL_POINTS Treats each vertex as a single point. Vertex n defin es point n. N points are drawn.

(16)

Drawing primitives

• GL_LINES Treats each pair of vertices as an independent line segment. Vertices 2n-1 and 2n define line n. N/2 lines are

drawn.

• GL_LINE_STRIP Draws a connected group of line segments from the first vertex to the last. Vertices n and n+1 define line n.

N-1 lines are drawn.

• GL_LINE_LOOP Draws a connected group of line segments from the first vertex to the last, then back to the first. Vertices n and n+1 define line n. The last line, however, is defined by

vertices N and 1. N lines are drawn.

(17)

Drawing primitives

• GL_TRIANGLES Treats each triplet of vertices as an

independent triangle. Vertices 3n-2, 3n-1, and 3n define triangle n. N/3 triangles are drawn.

• GL_TRIANGLE_STRIP Draws a connected group of triangles.

One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn.

• GL_TRIANGLE_FAN Draws a connected group of triangles.

One triangle is defined for each vertex presented after the first two vertices. Vertices 1, n+1, and n+2 define triangle n. N-2 triangles are drawn.

(18)

Triangle

(19)

Drawing primitives

• GL_QUADS Treats each group of four vertices as an

independent quadrilateral. Vertices 4n-3, 4n-2, 4n-1, and 4n define quadrilateral n. N/4 quadrilaterals are drawn.

• GL_QUAD_STRIP Draws a connected group of quadrilaterals.

One quadrilateral is defined for each pair of vertices presented after the first pair. Vertices 2n-1, 2n, 2n+2, and 2n+1 define quadrilateral n. N/2-1 quadrilaterals are drawn. Note that the

order in which vertices are used to construct a quadrilateral from strip data is different from that used with independent data.

• GL_POLYGON Draws a single, convex polygon. Vertices 1 through N define this polygon.

(20)

Quad

(21)

Basic primitives

• GL_LINES, GL_LINE_STRIP

(22)

Basic primitives

• GL_LINE_LOOP, GL_TRIANGLES

(23)

Basic primitives

• GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN

(24)

Basic primitives

• GL_QUADS, GL_POLYGON

(25)

OpenGL Naming Convension

• gl : gl library

• Vertex : command

• 2f : number and type of parameters

• OpenGL Data Type Presentation C-language GLbyte 8-bit integer signed char b GLshort 16-bit integer short s

GLint, GLsizei 32-bit integer long l GLfloat,GLclampf 32-bit float float f GLdouble,GLclampd 64-bit float double d

GLubyte,GLboolean 8-bit unsigned unsigned char ub GLushort 16-bit unsigned unsigned short us

GLuint,GLenum 32-bit unsigned unsigned long ui

(26)

glVertex[234][b s i f d ub us ui]{v}(*)

// allows 2 (x,y), 3 (x,y,z), or 4 (x,y,z,w) values // allows the following data types

// b signed char; 8 bit integer // s short; 16 bit integer

// i integer; 32 bit integer // f float; 32 bits

// d double; 64 bits

// ub unsigned byte; 8 bits // us unsigned short; 16 bits // ui unsigned int; 32 bits

// optional v  defined in an array (vector)

(27)

lab01.cpp

// lab01.cpp, Computer Graphics, lbg@dongseo.ac.kr

#include <stdio.h>

#include <stdlib.h>

#include <GL/glut.h>

GLint windowWidth, windowHeight, N=4;

void myAxis(void) {

int i;

glColor3f(0.98, .04, .70);

glBegin(GL_LINES);

for(i=1; i<N; i++) {

glVertex2i(i*windowWidth/N, 0);

glVertex2i(i*windowWidth/N, windowHeight);

glVertex2i(0, i*windowHeight/N);

glVertex2i(windowWidth, i*windowHeight/N);

} glEnd();

}

void myDraw(void) {

glColor3f(0.60, .40, .70);

glBegin(GL_POLYGON);

glVertex2i(windowWidth/N, windowHeight/N);

glVertex2i(3*windowWidth/N, windowHeight/N);

glVertex2i(3*windowWidth/N, 3*windowHeight/N);

glVertex2i(windowWidth/N, 3*windowHeight/N);

glEnd();

}

void myDisplay(void) {

glClear(GL_COLOR_BUFFER_BIT);

myAxis();

myDraw();

glFlush();

}

(28)

lab01.cpp

void myReshape(int width, int height) {

glClearColor (.75, .75, .75, 0.0);

glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(0, width, 0, height, -1, 1);

windowWidth=width;

windowHeight=height;

glMatrixMode(GL_MODELVIEW);

}

void main(int argc, char** argv) {

glutInit(&argc,argv);

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(0,0);

glutCreateWindow("lab01");

glutReshapeFunc(myReshape);

glutDisplayFunc(myDisplay);

glutMainLoop();

}

(29)

Lab 01

(30)

Lab 0101, 0102

• Homework1 : in two weeks

(31)

Lab 0103, 0104

(32)

Lab 0105, 0106

(33)

Lab 0107, 0108

(34)

Lab 0109

참조

관련 문서

• Clear the stencil, disable the write to the colour buffer, render the mirror, setting the stencil to 1 if the depth test passes.

There was a significant increase in new bone formation in the group in which toothash and plaster of Paris and either PRP or fibrin sealants were used, compared with the groups

The matrix A show the cost per computer (in thousands of dollars) and B the production figures for the year 2005 (in multiples of 1000 units).. Find a matrix C that

- Example) Suppose that a new product or facility is proposed and that the criterion for success is a 10 percent rate of return on the investment for a 5-year life of the

 Gray and black vertices, therefore, have been discovered, but breadth-first search distinguishes between them to ensure that the search proceeds in a breadth-first manner..

 enhanced by copolym’n with small portion of reactive group (like –CH 3 or = (diene)).  simple and versatile, but not

• Clique cover number: cardinality of a minimum clique cover. • Independent set: no two vertices in the

In the broad approach, a country would define a system of forest management practices (without the requirement that a specified forest management practice