_openglcl

Size: px
Start display at page:

Download "_openglcl"

Transcription

1 0 0 GPU Graphics Processing Unit CG GPU CG CG GPU OpenGL/GLSL CG D CG D CG GPU CG D CG D CG GPU CG GPU GPGPU General-Purpose computing on Graphics Processing Units GPU GPGPU OpenCL OpenCL OpenGL Windows MacOS Live Campus OpenGL Graphical Processing Unit google Graphics Processing Unit Graphical...

2

3 OpenGL OpenGL/GLSL CG 0. GPU CPU GPU GPU CPU API Application Program Interface OpenGL OpenGL CG DirectX, GLSL OpenGL Shading Language OpenGL GPU 0 OpenGL GPU API GPU OpenGL 0 GPU OpenGL CG OpenGL OpenGL DirectX Windows OpengL GPU APU Vulkan Metal Metal

4 OpenGL.: GLSL OpenGL GPU CG. OpenGL/GLSL CG. 0.. CG. OpenCL

5 OpenGL OpenGL OpenGL OpenGL PC OpenGL OpenGL PC OS CG OS OS OS OS PC OS API GLUT OpenGL Utility Toolkit GLUT CG GLUT OpenGL API GLUT MacOS deprecated API GLFW GLUT OpenGL gl GLUT glut OpenGL OpenGL/GLUT OpenGL GLUT GLFW

6 OpenGL GPU GPU 0 0 GPU Visual Studio Xcode OpenGL.. Metal Xcode

7 OpenGL. GPU OpenGL C OpenGL 0 vertex shader... vertex D CG GPU GPGPU fragment shader DirectX pixel= GLSL GLSL C C

8 OpenGL void display() /* */ int main() /* */ glutdisplayfunc(display); // callback glutmainloop(); // return 0;.: C.. OpenGL/GLSL GLUT. GLUT callback glutdisplayfunc(display) display() GLUT glutmainloop() 0 GLUT GLUT / glutdisplayfunc() display() void glutdisplayfunc(void (*func)(void)); func void glutmainloop(void);

9 OpenGL void initsystem() /* */ void initdata() /* */ void display() /* */ int main() initsystem(); initdata(); glutdisplayfunc(display); // callback glutmainloop(); // return 0;.: main initsystem() initdata(). 0. CG.

10 OpenGL.: OpenGL DirectX Metal Unity / /. OpenGL... GLuint program; 0

11 OpenGL #include <iostream> using namespace std; #include <stdio.h> #include <stdlib.h> #if defined(win) # pragma comment(lib, "glew.lib") # include "glew.h" # include "glut.h" # include "glext.h" #elif defined( APPLE ) defined(macosx) # include <GLUT/glut.h> #else # define GL_GLEXT_PROTOTYPES # include <GL/glut.h> #endif void initsystem(int argc, char *argv[]); void initdata(); void display(void); GLuint compileprogram(glenum type, const GLchar *file);.: program OpenGL name of a program object name. glutinit(&argc, argv) 0 GLUT int argc, char *argv[] 0. glutinitdisplaymode(glut RGBA GLUT SINGLE) 0 void glutinit(int *argcp, char **argv); void glutinitdisplaymode(unsigned int mode);

12 OpenGL GLuint program; void initsystem(int argc, char *argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); #if defined(win) glewinit(); #endif GLuint vs = compileprogram(gl_vertex_shader, "shader.vert"); GLuint fs = compileprogram(gl_fragment_shader, "shader.frag"); program = glcreateprogram(); glattachshader(program, vs); glattachshader(program, fs); gllinkprogram(program); gluseprogram(program);.: GLUT RGBA GLUT SINGLE CG GLUT SINGLE GLUT DOUBLE. glutinitwindowsize(,). void glutinitwindowsize(int width, int height); void glutinitwindowposition(int x, int y);

13 OpenGL glutcreatewindow("test Window") Test Window. glclearcolor(0.,0.,0.,) (r, g, b, a) =(0., 0., 0., )..0 glclear() 0. glewinit(); Windows MacOS glew Windows. GLuint vs = compileprogram(gl VERTEX SHADER, "shader.vert") 0 compileprogram(). OpenGL GL VERTEX SHADER shader.vert.. int glutcreatewindow(char *name); name int void glutsetwindow(int win); void glclearcolor(glfloat red, GLfloat green, GLfloat blue, GLfloat alpha); GLfloat float

14 OpenGL GLuint fs = compileprogram(gl FRAGMENT SHADER, "shader.frag") 0. program = glcreateprogram() program. 0 glattachshader(program, vs) glattachshader(program, fs) vs fs program. gllinkprogram(program) program GPU. gluseprogram(program) 0 program GPU compileprogram(). GLuint glcreateprogram(void); void glattachshader(gluint program, GLuint shader); void gllinkprogram(gluint program); void gluseprogram(gluint program);

15 OpenGL GLuint compileprogram(glenum type, const GLchar *file) FILE* fp = fopen(file, "r"); #define MAX_SHADER_FILE_SIZE 0000 GLchar ftext[max_shader_file_size]; unsigned long n = fread(ftext,, MAX_SHADER_FILE_SIZE, fp); ftext[n] = \0 ; fclose(fp); GLuint shader = glcreateshader(type); const GLchar* ftext_handle = ftext; glshadersource(shader,, &ftext_handle, NULL); glcompileshader(shader); return shader;.:. FILE* fp = fopen(file, "r"); #define MAX_SHADER_FILE_SIZE 0000 GLchar ftext[max_shader_file_size]; unsigned long n = fread(ftext,, MAX_SHADER_FILE_SIZE, fp); ftext[n] = \0 ; fclose(fp); 0 ftext 0KB. GLuint shader = glcreateshader(type) 0 GL VERTEX SHADER GL FRAGMENT SHADER. const GLchar* ftext handle = ftext; 0 GLuint glcreateshader(glenum shadertype);

16 OpenGL ftext ftext handle. glshadersource(shader,, &ftext handle, NULL). glcompileshader(shader); 0. CG.. 0. const int NUM POINTS = ; display().0 void glshadersource(gluint shader,glsizei count,const GLchar **string,const GLint *length); void glcompileshader(gluint shader)

17 OpenGL const int NUM_POINTS = ; void initdata() float pos[*num_points]; pos[0] = -0.; pos[] = -0.; pos[] = +0.; pos[] = +0.; pos[] = +0.; pos[] = -0.; pos[] = -0.; pos[] = +0.; // GLuint bufid; // glgenbuffers(, &bufid); glbindbuffer(gl_array_buffer, bufid); glbufferdata(gl_array_buffer, sizeof(float)**num_points, pos, GL_STATIC_DRAW); GLint p = glgetattriblocation(program,"position"); glvertexattribpointer(p,, GL_FLOAT, GL_FALSE, 0, 0); glenablevertexattribarray(p); gllinewidth(0);.:. initdata() float pos[*num POINTS]; 0 float NUM POINTS *NUM POINTS GPU double float CG RGB CG GPU 0 NVIDIA Telsa GPGPU GPU

18 OpenGL bit float. 0 (a) x y... x y... (b) pos[0] = -0.; pos[] = -0.; 0 (x, y) =( 0., 0.).... GLuint bufid; glenablevertexattribarray(p); pos GPU. OpenGL (a) OpenGL OpenGL GPU GPU Buffer Object

19 OpenGL pos... attribute vec position;....: GPU (a) OpenGL bufid (b) bufid Vertex Buffer Object (c) bufid GPU CPU (d) attribue p (e) bufid p glgenbuffers(, &bufid) 0 OpenGL. budid OpenGL name GLuint (b) OpenGL void glgenbuffers(glsizei n, GLuint * buffers); n buffer

20 OpenGL 0 0 glbindbuffer(gl ARRAY BUFFER, bufid) bufid GL ARRAY BUFFER GL ARRAY BUFFER Vertex Buffer Object VBO (c) glbufferdata(gl ARRAY BUFFER, sizeof(float)**num POINTS, pos, GL STATIC DRAW) i. GL ARRAY BUFFER glbindbuffer() bufid GL ARRAY BUFFER bufid ii. sizeof(float)**num POINTS GPU iii. pos GPU CPU NULL CPU GPU glbufferdata() iv. GL STATIC DRAW GPU void glbindbuffer(glenum target, GLuint buffer); target OpenGL void glbufferdata(glenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); glmapbuffer() glunmapbuffer() glbuffersubdata() 0

21 OpenGL 0 0 GL STREAM DRAW GL STATIC COPY GL DYNAMIC READ (d) GPU. GLint p = glgetattriblocation(program,"position"); program attribute "position" location p. attribute vec position; (e) glvertexattribpointer(p,, GL FLOAT, GL FALSE, 0, 0) 0 i. p arrribute glgetattriblocation() "position" VBO glbindbuffer() bufid VBO arrribute ii. VBO A. arrribute,, GLint glgetattriblocation(gluint program, const GLchar *name); 0 void glvertexattribpointer(gluint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer);

22 OpenGL 0 0 B. GL FLOAT float GL BYTE GL UNSIGNED BYTE GL SHORT GL UNSIGNED SHORT GL INT GL UNSIGNED INT. attribute vec position; position vec float C. GL FALSE, 0, 0 (f) glenablevertexattribarray(p) p arrribute (g) gllinewidth(0).0 display() initdata() display().0. gluseprogram(program) initsystem() void glenablevertexattribarray(gluint index); void gllinewidth(glfloat width);

23 OpenGL void display(void)// gluseprogram(program); glclear(gl_color_buffer_bit); gldrawarrays(gl_lines,0,num_points); glflush();.0:. glclear(gl COLOR BUFFER BIT). glclearcolor(0.,0.,0.,) GL COLOR BUFFER BIT D CG. gldrawarrays(gl LINES,0,NUM POINTS) 0 0 gluseprogram(program) (a)... GL POINTS... GL LINES, GL LINE STRIP, GL LINE LOOP... GL TRIANGLES, GL TRIANGLE STRIP, GL TRIANGLE FAN GL LINES (b) initdata() 0 0 void glclear(glbitfield mask); void gldrawarrays(glenum mode, GLint first, GLsizei count);

24 OpenGL int main(int argc, char *argv[]) initsystem(argc,argv); initdata(); glutdisplayfunc(display); glutmainloop(); return 0;.: (c) NUM POINTS.. glflush() 0 gldrawarrays() gldrawarrays() gldrawarrays() PC glflush() OpenGL main.... OpenGL/GLSL... void glflush(void);

25 OpenGL #version 0 attribute vec position; void main(void) gl_position = vec(position,0.0,.0);.:. #version 0 GLSL.. attribute attribute vec position; position initdata() initdata(). main 0 gl Position = vec(position,0.0,.0); vec gl Position (x, y, z, w) (X, Y, Z) =( x w, y w, z w ) OpenGL.0 X.0,.0 Y.0,.0 Z.0, w > 0

26 OpenGL #version 0 void main(void) gl_fragcolor = vec(.0, 0.0, 0.0, 0.0);.:.0 X.0.0 Y.0 (X, Y ) Z attribute position x px y py vec(position,0.0,.0) (x, y, z, w) =(px, py, 0.0,.0) 0.0,.0 px, py (X, Y,Z) =(px, py, 0.0).0 px.0,.0 py.0... main gl FragColor = vec(.0, 0.0, 0.0, 0.0); 0 vec gl FragColor 0 (.0, 0.0, 0.0, 0.0).

27 OpenGL.: GPU initdata() attribute position GPU gl Position gldrawarrays() GL LINES gl FragColor GPU

28 OpenGL D CG..

29 OpenGL struct PositionD float x; float y; ;.: struct ArrayBuffer GLuint bufid; // int size; // attribute ; ArrayBuffer(float* data, int s, int n); //.:... PositionD. PositionD 0.. ArrayBuffer. ArrayBuffer GPU. class struct class class ArrayBuffer public:... struct

30 OpenGL struct Shader GLuint program; // Shader(const char* vsn, const char* fsn); void use(); // // ; void bindarraybuffer(const char* vname, ArrayBuffer* ap); //attribute void run(glenum mode, int n); // GLuint compileprogram(glenum type, const GLchar *file); // void buildprogram(const GLchar *vsfile, const GLchar *fsfile); //.: ArrayBuffer(float* data, int s, int n)... float float attribute float bufid size 0.. Shader. Shader.. Shader(const char* vsn, const char* fsn)... void use()... void bindarraybuffer(const char* vname, ArrayBuffer* ap)... attribute 0

31 OpenGL Shader *sp;// void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); #if defined(win) glewinit(); #endif sp = new Shader("shader.vert","shader.frag"); // sp->use();.: initsystem() attribute ArrayBuffer void run(glenum mode, int n)... GL LINES program compileprogram() buildprogram().. initsystem() initdata() display() ArrayBuffer. Shader.

32 OpenGL const int NUM_POINTS = ;// void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; pos[].x = -0.; pos[].y = +0.; ArrayBuffer ab((float*)pos,, NUM_POINTS); // sp->bindarraybuffer("position",&ab); //position ab gllinewidth(0.0);.: initdata() void display(void) glclear(gl_color_buffer_bit); sp->run(gl_lines,num_points);.0: display() ArrayBuffer::ArrayBuffer(float* data, int s, int n) size = s; glgenbuffers(, &bufid); glbindbuffer(gl_array_buffer, bufid); glbufferdata(gl_array_buffer, sizeof(float)*size*n, data, GL_STATIC_DRAW);.: ArrayBuffer

33 OpenGL Shader::Shader(const char* vsn, const char* fsn) buildprogram(vsn, fsn); void Shader::use() gluseprogram(program); void Shader::bindArrayBuffer(const char* vname, ArrayBuffer* ap) glbindbuffer(gl_array_buffer, ap->bufid); GLint p = glgetattriblocation(program,vname); glvertexattribpointer(p, ap->size, GL_FLOAT, GL_FALSE, 0, 0); glenablevertexattribarray(p); void Shader::run(GLenum mode, int n) gldrawarrays(mode,0,n); glflush(); GLuint Shader::compileProgram(GLenum type, const GLchar *file) FILE* fp = fopen(file, "r"); #define MAX_SHADER_FILE_SIZE 0000 GLchar ftext[max_shader_file_size]; unsigned long n = fread(ftext,, MAX_SHADER_FILE_SIZE, fp); ftext[n] = \0 ; fclose(fp); GLuint shader = glcreateshader(type); const GLchar* ftext_handler = (const GLchar*)&ftext; glshadersource(shader,, &ftext_handler, NULL); glcompileshader(shader); return shader; void Shader::buildProgram(const GLchar *vsfile, const GLchar *fsfile) GLuint vs = compileprogram(gl_vertex_shader, vsfile); GLuint fs = compileprogram(gl_fragment_shader, fsfile); program = glcreateprogram(); glattachshader(program, vs); glattachshader(program, fs); gllinkprogram(program);.: Shader

34 OpenGL void Shader::buildProgram(const GLchar *vsfile, const GLchar *fsfile) GLuint vs = compileprogram(gl_vertex_shader, vsfile); GLuint fs = compileprogram(gl_fragment_shader, fsfile); program = glcreateprogram(); glattachshader(program, vs); glattachshader(program, fs); gllinkprogram(program); GLint status; glgetshaderiv(program, GL_LINK_STATUS, &status); if (!status) cerr << "program link error: " << endl; GLsizei infologlength; glgetprogramiv(program, GL_INFO_LOG_LENGTH, &infologlength); GLchar * infolog = new GLchar[infologLength]; if (infolog == NULL) cerr << "ERROR: Could not allocate InfoLog buffer" << endl; else int charswritten = 0; glgetprograminfolog(program, infologlength, &charswritten, infolog); cerr << "Program InfoLog:" << endl << infolog << endl; delete infolog; exit();.: 0.. Shader::compileProgram() Shader::buildProgram().. cerr attribute attribute Shader::bindArrayBuffer() attribute p..

35 OpenGL GLuint Shader::compileProgram(GLenum type, const GLchar *file) FILE* fp = fopen(file, "r"); #define MAX_SHADER_FILE_SIZE 0000 GLchar ftext[max_shader_file_size]; unsigned long n = fread(ftext,, MAX_SHADER_FILE_SIZE, fp); ftext[n] = \0 ; fclose(fp); GLuint shader = glcreateshader(type); const GLchar* ftext_handler = (const GLchar*)&ftext; glshadersource(shader,, &ftext_handler, NULL); glcompileshader(shader); GLint status; glgetshaderiv(shader, GL_COMPILE_STATUS, &status); if (!status) cerr << "shader compile error: " << file << endl; GLsizei infologlength; glgetprogramiv(shader, GL_INFO_LOG_LENGTH, &infologlength); GLchar * infolog = new GLchar[infologLength]; if (infolog == NULL) cerr << "ERROR: Could not allocate InfoLog buffer" << endl; else int charswritten = 0; glgetshaderinfolog(shader, infologlength, &charswritten, infolog); cerr << "Shader InfoLog:" << endl << infolog << endl; delete infolog; exit(); return shader;.:

36 OpenGL void Shader::bindArrayBuffer(const char* vname, ArrayBuffer* ap) glbindbuffer(gl_array_buffer, ap->bufid); GLint p = glgetattriblocation(program,vname); if(p < 0) cerr << "attribute name error: "<< vname << endl; exit(); glvertexattribpointer(p, ap->size, GL_FLOAT, GL_FALSE, 0, 0); glenablevertexattribarray(p);.: Shader::bindArrayBuffer() attribute

37 OpenGL.:.. attribute position attribute attribute. p p B B p B B = p p p p B + p p p p B (.) GPU 0... initdata() bri ArrayBuffer in brightness attribute

38 OpenGL void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; pos[].x = -0.; pos[].y = +0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); float bri[num_points]; bri[0] = 0.0; bri[] =.0; bri[] = 0.0; bri[] =.0; ArrayBuffer ab((float*)bri,,num_points); sp->bindarraybuffer("in_brightness",&ab); gllinewidth(0.0);.: initdata()... attribute in brightness out brightness varying varying main in brightness out brightness 0... varying out brightness

39 OpenGL #version 0 attribute vec position; attribute float in_brightness; varying float out_brightness; void main(void) gl_position = vec(position,0.0,.0); out_brightness = in_brightness;.: #version 0 varying float out_brightness; void main(void) gl_fragcolor = vec(out_brightness, 0.0, 0.0, 0.0);.: varying out brightness main out brightness RGB GPU

40 OpenGL.0:.: RGB RGB.. RGB float attribute GPU attribute float RGB attribute. RGB 0

41 OpenGL struct RGB float r; float g; float b; ;.: RGB p p RGB C C p RGB C C = p p p p C + p p p p C (.) GPU.. RGB.. initdata() rgb RGB ArrayBuffer in color attribute 0... attribute in color RGB varying out color vec float vec RGB...

42 OpenGL void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; pos[].x = -0.; pos[].y = +0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); RGB rgb[num_points]; rgb[0].r =.0; rgb[0].g =.0; rgb[0].b =.0; // rgb[].r =.0; rgb[].g = 0.0; rgb[].b = 0.0; // rgb[].r = 0.0; rgb[].g =.0; rgb[].b = 0.0; // rgb[].r = 0.0; rgb[].g = 0.0; rgb[].b =.0; // ArrayBuffer ab((float*)rgb,,num_points); sp->bindarraybuffer("in_color",&ab); gllinewidth(0.0);.: RGB initdata() varying main out color out color vec gl FragColor vec RGB RGB RGB

43 OpenGL #version 0 attribute vec position; attribute vec in_color; varying vec out_color; void main(void) gl_position = vec(position,0.0,.0); out_color = in_color;.: RGB #version 0 varying vec out_color; void main(void) gl_fragcolor = vec(out_color, 0.0);.: RGB.:

44 OpenGL.: 0. point sprite 0 0 PC sprite GPU RGB.

45 OpenGL void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); #if defined(win) glewinit(); #endif glenable(gl_point_sprite); // glenable(gl_vertex_program_point_size); // sp = new Shader("shader.vert","shader.frag"); sp->use();.: initsystem()... glenable(gl POINT SPRITE) gl PointSize gl PointSize glenable(gl VERTEX PROGRAM POINT SIZE) 0 gl PointSize. initsystem() initdata().. display() void glenable(glenum cap); cap OpenGL OpenGL void gldisable(glenum cap);

46 OpenGL void display(void)// glclear(gl_color_buffer_bit); sp->run(gl_points,num_points); // GL_POINTS.: display() #version 0 attribute vec position; attribute vec in_color; varying vec out_color; void main(void) gl_position = vec(position,0.0,.0); out_color = in_color; gl_pointsize = 0; //.0:...0 gl PointSize gl PointSize N (x, y) N N GL POINT SIZE MAX

47 OpenGL.:

48 OpenGL.: gl PointCoord vec. [0, ] [0, ] gl PointCoord. [0, ] [0, ] [, ] [, ] vec xy xy length(xy) = xy =sqrt(xy.x*xy.x+xy.y*xy.y).0 out color length() vec vec vec GLSL length(xy)

49 OpenGL #version 0 varying vec out_color; void main(void) vec xy =.0*gl_PointCoord-vec(.0,.0); if(length(xy) <.0) gl_fragcolor = vec(out_color, 0.0); else discard;.: gl_pointcoord.y 0 0 gl_pointcoord.x.: gl PointCoord discard discard....

50 OpenGL.: 0

51 OpenGL.: 0. =polygon CG triangular polygon. p p p p (λ,λ,λ ) λ = p q p q, λ = p q p q, λ = p q p q (.). RGB C C C p RGB C C = λ C + λ C + λ C (.) (λ,λ,λ ) GPU

52 OpenGL p q 0 p p λ q λ λ q p 0.: RGB.. initdata(). OpenGL initsystem().. display() GL TRIANGLES

53 OpenGL const int NUM_POINTS = ; // void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); RGB rgb[num_points]; rgb[0].r =.0; rgb[0].g =.0; rgb[0].b =.0; rgb[].r =.0; rgb[].g = 0.0; rgb[].b = 0.0; rgb[].r = 0.0; rgb[].g =.0; rgb[].b = 0.0; ArrayBuffer ab((float*)rgb,,num_points); sp->bindarraybuffer("in_color",&ab); gllinewidth(0.0); //.: initdata() void display(void)// glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points); //.: display().0:

54 OpenGL.0 initsystem() initdata() display() main() Shader void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); #if defined(win) glewinit(); #endif // // glenable(gl_point_sprite); glenable(gl_vertex_program_point_size); sp = new Shader("shader.vert","shader.frag"); sp->use();.: initsystem()

55 OpenGL void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); RGB rgb[num_points]; rgb[0].r =.0; rgb[0].g =.0; rgb[0].b =.0; rgb[].r =.0; rgb[].g = 0.0; rgb[].b = 0.0; rgb[].r = 0.0; rgb[].g =.0; rgb[].b = 0.0; ArrayBuffer ab((float*)rgb,,num_points); sp->bindarraybuffer("in_color",&ab); // gllinewidth(0.0);.: initdata() void display(void) glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points);/.: display() int main(int argc, char *argv[]) initsystem(argc,argv); initdata(); glutdisplayfunc(display); glutmainloop(); return 0;.: main()

56 OpenGL #version 0 attribute vec position; attribute vec in_color; varying vec out_color; void main(void) gl_position = vec(position,0.0,.0); out_color = in_color;.: #version 0 varying vec out_color; void main(void) gl_fragcolor = vec(out_color, 0.0);.:

57 OpenGL.: 0 0. attribute uniform.. 0 uniform uniform GPU. uniform uniform uniform uniform

58 OpenGL.: attribute uniform uniform.. Shader float uniform void setfloat(const char* vname, float val); Shader uniform. GLint p = glgetuniformlocation(program, vname); 0 vname uniform location p glgetuniformlocation(). glgetattriblocation() uniform attribute uniform GLint glgetuniformlocation(gluint program, const GLchar *name);

59 OpenGL void Shader::setFloat(const char* vname, float val) GLint p = glgetuniformlocation(program, vname); if(p < 0) cerr << "uniform name error: " << vname << endl; exit(); gluniformf(p,val);.: Shader::setFloat() void display(void) sp->setfloat("theta",0*m_pi/0.0); glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points);.0: uniform display() p. gluniformf(p,val) 0 uniform float val gluniformf() gluniformf() gluniformf() gluniformf() vec vec vec uniform gluniformi() int uniform 0... uniform theta θ.0 0 void gluniformf(glint location, GLfloat v0); void gluniformf(glint location, GLfloat v0, GLfloat v); void gluniformf(glint location, GLfloat v0, GLfloat v, GLfloat v); void gluniformf(glint location, GLfloat v0, GLfloat v, GLfloat v, GLfloat v); void gluniformi(glint location, GLint v0);

60 OpenGL #version 0 attribute vec position; attribute vec in_color; varying vec out_color; uniform float theta; // void main(void) float x = cos(theta)*position.x-sin(theta)*position.y; // float y = sin(theta)*position.x+cos(theta)*position.y; // gl_position = vec(x,y,0.0,.0); out_color = in_color;.: display() theta 0 = 0 π/0 sp->setfloat("theta",0*m PI/0.0) initdata() CG display()... theta uniform attribute position gl Position 0... attribute uniform theta cos(theta) sin(theta) unifrorm cos(theta) sin(theta) 0

61 OpenGL theta.:. uniform. theta.. 0. uniform theta. cos(theta) cos(theta) = cos(0 π/0) =

62 OpenGL.: 0 #version 0 varying vec out_color; uniform float theta; void main(void) gl_fragcolor = vec(out_color.r, out_color.g, cos(theta), 0.0);.: uniform vec.x.y.z.r.g.b. CG. CG CG CG glut glut OpenGL

63 OpenGL theta.: CG main glutmainloop() gluttimerfunc(0, timer, ) glut 0 timer() void gluttimerfunc(unsigned int msecs, void (*func)(int value), value);

64 OpenGL t t t t t.:

65 OpenGL void initsystem() /* */ void initdata() /* */ void display() /* */ void timer(int num) // glutpostredisplay(); // glutdisplayfunc() gluttimerfunc(0, timer, num+); // 0 timer(num+) int main() initsystem(); initdata(); glutdisplayfunc(display); gluttimerfunc(0, timer, ); // 0 timer() glutmainloop(); return 0;.: CG timer() glutpostredisplay() glut display() glutdisplayfunc(display) display() timer() display() glutmainloop() void glutpostredisplay(void);

66 OpenGL void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_DOUBLE); //SINGLE DOUBLE glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); #if defined(win) glewinit(); #endif glenable(gl_point_sprite); glenable(gl_vertex_program_point_size); sp = new Shader("shader.vert","shader.frag"); sp->use();.: initsystem() void Shader::run(GLenum mode, int n) gldrawarrays(mode,0,n); glutswapbuffers(); // glflush();.: Shader::run() timer() 0 timer() main gluttimerfunc(0, timer, ) gluttimerfunc(0, timer, num+) timer() num timer() num timer() 0 000/0 = 0 FPS Frames Per Sec 0 0 OpenGL. GLUT SINGLE GLUT DOUBLE GPU

67 OpenGL double theta = 0.0; // void display(void) sp->setfloat("theta",theta); // uniform glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points); theta += 0.0; //.0: display(). Shader run()... glutswapbuffers() 0.0 uniform theta 0.0 theta sp->setfloat("theta",theta) GPU uniform theta FPS rad. 0 0/ =. initdata(). CG CG CG void glutswapbuffers(void);

68 OpenGL

69 CG texture D CG GPU. 0.. TextureD ArrayBuffer... TextureD TextureD(int tnum, void* data, int w) tnum 0 0 data RGBA w data.

70 .: struct TextureD GLuint texid; // GLint num; // ; TextureD(int tnum, void* data, int w);.: TextureD. num = tnum; TextureD num. glgentextures(, &texid). glgenbuffers(, &bufid) OpenGL bufid void glgentextures(glsizei n, GLuint * textures); 0

71 TextureD::TextureD(int tnum, void* data, int w) num = tnum; glgentextures (, &texid); glbindtexture(gl_texture_d,texid); gltexparameteri(gl_texture_d, GL_GENERATE_MIPMAP, GL_FALSE); gltexparameteri(gl_texture_d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glteximaged(gl_texture_d, 0, GL_RGBA, w, 0, GL_RGBA, GL_FLOAT, data);.: TextureD. glbindtexture(gl TEXTURE D,texID) GL TEXTURE D texid OpenGL. OpenGL. gltexparameteri(gl TEXTURE D, GL GENERATE MIPMAP, GL FALSE) 0 texid GL GENERATE MIPMAP GL FALSE gltexparameteri() D CG. void glbindtexture(glenum target, GLuint texture); void gltexparameteri(glenum target, GLenum pname, GLint param);

72 gltexparameteri(gl TEXTURE D, GL TEXTURE MAG FILTER, GL NEAREST) GL NEAREST RGBA... gltexparameteri(gl TEXTURE D, GL TEXTURE MIN FILTER, GL NEAREST) 0 RGBA GL NEAREST MIPMAP NEAREST GL LINEAR MIPMAP NEAREST GL NEAREST GL LINEAR GL NEAREST GL LINEAR. glteximaged(gl TEXTURE D, 0, GL RGBA, w, 0, GL RGBA, GL FLOAT, data) 0 GPU GPU GL TEXTURE D level of detail 0 0 RGBA GL RGBA w void glteximaged(glenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * data);

73 0 0 RGBA GL RGBA float GL FLOAT data data initdata() float RGBA 0.. Shader TextureD ArrayBuffer. glgen...() OpenGL glbind...() ArrayBuffer TextureD ArrayBuffer Shader. void Shader::bindArrayBuffer(const char* vname, ArrayBuffer* ap) TextureD void Shader::bindTexture(const char* vname, TextureD* tp). glbindtexture(gl TEXTURE D,tp->texID) TextureID

74 void Shader::bindTexture(const char* vname, TextureD* tp) glbindtexture(gl_texture_d,tp->texid); GLint p = glgetuniformlocation(program, vname); if(p < 0) cerr << "textured name error: "<< vname << endl; exit(); gluniformi(p, tp->num); glactivetexture(gl_texture0+(tp->num));.: Shader::bindTexture() GLint p = glgetuniformlocation(program, vname); vname uniform location p uniform p gluniformi(p, tp->num) 0 uniform tp->num tp->num. glactivetexture(gl TEXTURE0+(tp->num)) GPU GL TEXTURE0...0 initdata().. RGBA bit initdata()

75 struct RGBA float r; float g; float b; float a; ; // bit void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); float u[num_points]; u[0] = 0.0; u[] =.0; u[] =.0; // ArrayBuffer ab(u,,num_points); // ArrayBuffer sp->bindarraybuffer("in_u",&ab); // RGBA tex[]; for(int i = 0; i < ; i++) tex[i].r = i%; tex[i].g = i%; tex[i].b = i%; tex[i].a = 0.0; TextureD t(0,tex,); sp->bindtexture("tex",&t); // // // TextureD //.: initdata()

76 float u [0, ] u ArrayBuffer ab(u,,num_points); sp->bindarraybuffer("in_u",&ab); 0 attribute in u. gltextimaged() RGBA GL RGBA gltextimaged() GL FLOAT tex RGBA for(int i = 0; i < ; i++) tex[i].r = i%; tex[i].g = i%; tex[i].b = i%; tex[i].a = 0.0; (r, g, b, a) =(0, 0, 0, 0), (,,, 0), (0, 0, 0, 0),..., 0... TextureD tex initsystem() display() main() float

77 #version 0 attribute vec position; attribute float in_u; varying float out_u; void main(void) gl_position = vec(position,0.0,.0); out_u = in_u; //.: #version 0 varying float out_u; uniform samplerd tex; void main(void) gl_fragcolor = textured(tex,out_u);.: 0... varying out u uniform GLSL samplerd uniform samplerd tex; OpenGL OpenGL/GLSL

78 : tex : textured(tex,out u) tex out u RGBA [0, ]. [0, ] RGBA textured(tex,out u) 0... uniform vec textured(samplerd s, float coord)

79 :.: 0 tex RGBA. D CG OpenGL/GLSL...

80 TextureD t(0,tex,); TextureD t(0,tex,); RGBA for(int i = 0; i < ; i++) tex[i].r = i%; tex[i].g = i%; tex[i].b = i%; tex[i].a = 0.0; // 0 for(int i = 0; i < ; i++) tex[i].r = i%; // 0.0,.0, 0.0,.0, 0.0, 0.0,... tex[i].g = (i%)/.0; // 0.0, 0.,.0, 0.0, 0.,.0,... tex[i].b = (i%)/.0; // 0.0, 0., 0.,.0, 0.0, 0.,.. tex[i].a = 0.0;.... u[0] = 0.0; u[] =.0; u[] =.0; 0 u[0] = 0.0; u[] =.0; u[] = 0.; //. 0

81 .:.:

82 .: [0, ].. [0, ] u[0] = 0.0; u[] =.0; u[] = 0.; u[0] = -.0; // u[] =.0; // u[] = 0.; OpenGL/GLSL [0, ] x x = mod (x,.0) [0, ] x x x x x 0 x =0 x x x x-x.

83 x x.: x x.: [0, ].. [0, ] x <0 x =0 x > x = x-x.. gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);. 0.. TextureD

84 .: gltexparameteri(gl TEXTURE D, GL TEXTURE MAG FILTER, GL NEAREST); ; gltexparameteri(gl TEXTURE D, GL TEXTURE MAG FILTER, GL LINEAR); ; GL NEAREST GL LINEAR. GL NEAREST RGBA GL LINEAR RGBA RGBA x =0., 0., 0., 0. 0 GL NEAREST x RGBA GL LINEAR x x x< x x x RGBA x <0. x>0..

85 .: :

86

87 .0:.... gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_REPEAT); 0 GL TEXTURE WRAP S GL REPEAT [0, ]. [0, ]

88 :

89 .: struct TextureD GLuint texid; // GLint num; // ; TextureD(int tnum, void* data, int w, int h);.: TextureD.... TextureD. TextureD TextureD(int tnum, void* data, int w, int h) h data

90 TextureD::TextureD(int tnum, void* data, int w, int h) num = tnum; glgentextures (, &texid); glbindtexture(gl_texture_d,texid); gltexparameteri(gl_texture_d, GL_GENERATE_MIPMAP, GL_FALSE); gltexparameteri(gl_texture_d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glteximaged(gl_texture_d, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_FLOAT, data);.: TextureD.. OpenGL target GL TEXTURE D GL TEXTURE D 0 glteximaged(gl TEXTURE D, 0, GL RGBA, w, h, 0, GL RGBA, GL FLOAT, data) GPU OpenGL h.. Shader Shader void Shader::bindTexture(const char* vname, TextureD* tp) void glteximaged(glenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data); 0

91 void Shader::bindTexture(const char* vname, TextureD* tp) glbindtexture(gl_texture_d,tp->texid); GLint p = glgetuniformlocation(program, vname); if(p < 0) cerr << "textured name error: "<< vname << endl; exit(); gluniformi(p, tp->num); glactivetexture(gl_texture0+(tp->num));.: Shader::bindTexture() Texture TextureD TextureD.: 0. GL TEXTURE D GL TEXTURE D.... overload override.. initdata()... PositionD uv

92 void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); PositionD uv[num_points]; // uv[0].x = 0.0; uv[0].y = 0.0; uv[].x =.0; uv[].y =.0; uv[].x =.0; uv[].y = 0.0; ArrayBuffer ab((float*)uv,,num_points); sp->bindarraybuffer("in_uv",&ab); RGBA tex[][]; // for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = (i+j)%; tex[j][i].b = (i+j)%; tex[j][i].a = 0.0; TextureD t(0,tex,,); sp->bindtexture("tex",&t);.: initdata() u v uv.. [0, ].. [0, ]. uv[i] [0, ] [0, ] uv attribute attribute in uv. tex RGBA

93 #version 0 attribute vec position; attribute vec in_uv; varying vec out_uv; void main(void) gl_position = vec(position,0.0,.0); out_uv = in_uv;.: for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = (i+j)%; tex[j][i].b = (i+j)%; tex[j][i].a = 0.0; 0 TextureD tex uniform. initsystem() display() main()... in uv 0... varying out uv

94 #version 0 varying vec out_uv; uniform samplerd tex; void main(void) gl_fragcolor = textured(tex,out_uv);.: textured(tex,out u) tex out uv RGBA...0 uniform tex RGBA vec textured(samplerd s, vec coord)

95 (.0,.0) (0.0,0.0) (.0,0.0).0 tex (0., 0.) (0., 0.) (0., 0.) (0.0, 0.0) (0., 0.0) (0., 0.0) (0., 0.) (0., 0.) (0., 0.) (0., 0.0) (0., 0.) (0., 0.) (0., 0.) (0., 0.) (0., 0.0) (.0,.0) (.0, 0.) (.0, 0.) (.0, 0.) (.0, 0.) (.0, 0.0).0:

96 .: RGBA tex[][]; for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = (i+j)%; tex[j][i].b = (i+j)%; tex[j][i].a = 0.0; TextureD t(0,tex,,);.

97 .: for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = (i+j)%; tex[j][i].b = (i+j)%; tex[j][i].a = 0.0;.. for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = ((i+j)%)/.0; tex[j][i].b = ((i+j)%)/.0; tex[j][i].a = 0.0;.

98 .: uv[0].x = 0.0; uv[0].y = 0.0; uv[].x =.0; uv[].y =.0; uv[].x =.0; uv[].y = 0.0; uv[0].x = 0.0; uv[0].y = 0.0; uv[].x =.0; uv[].y =.0; uv[].x = 0.; uv[].y = 0.0; // uv[].x.

99 .: [0, ] [0, ] 0.. [0, ] uv[0].x = 0.0; uv[0].y = 0.0; uv[].x =.0; uv[].y =.0; uv[].x = 0.; uv[].y = 0.0; uv[0].x = -.0; uv[0].y = -.0; uv[].x =.0; uv[].y =.0; uv[].x = 0.; uv[].y = -.0; [0, ] [0, ]. [0, ].

100 .:.. [0, ] [0, ] gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);. GL TEXTURE WRAP S GL TEXTURE WRAP T gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 0. S T (u, v) (s, t) 0 00

101 .:.. gltexparameteri(gl TEXTURE D, GL TEXTURE MAG FILTER, GL NEAREST); ; gltexparameteri(gl TEXTURE D, GL TEXTURE MAG FILTER, GL LINEAR); ;. bilinear interpolation. A B C D V A V B V C V D P =(p s,p t ) 0 p s,p t V P V P =( p s ) ( p t ) V A + p s ( p t ) V B +( p s ) p t V C + p s p t V D GPU OpenGL 0 OpenGL R S T U U u-v 0

102 .:.0 C D P=(p s,p t ) 0.0 A B.0.: 0

103 .:.... gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_S, GL_REPEAT); gltexparameteri(gl_texture_d, GL_TEXTURE_WRAP_T, GL_REPEAT);. 0.. jpeg. RGBA. GPU 0

104 第 章 テクスチャの利用 図.0: 元画像 理工学部 号館 図.: 画像例 その 理工学部 号館 の画像を三角形に張る たとえば 図. は 理工学部 号館の画像 図.0 をその方法で取り込み 描画した ものである 具体的には 図. の以下のプログラム片 RGBA tex[][]; // テクスチャデータの設定 for(int i = 0; i < ; i++) for(int j = 0; j < ; j++) tex[j][i].r = (i+j)%; tex[j][i].g = (i+j)%; tex[j][i].b = (i+j)%; tex[j][i].a = 0.0; TextureD t(0,tex,,); sp->bindtexture("tex",&t); 0 の部分を // 画像ファイルおよび画像の水平 垂直サイズの読み込み int imgw,imgh; RGBA* img = loadjpegimage("build.jpg",*imgw,*imgh); TextureD t(0,img,imgw,imgh); sp->bindtexture("tex",&t); 0 などに置き換えればよい loadjpegimage() を画像を読み込む関数とするが それにつ 0

105 :.. 0

106 #include <iostream> using namespace std; #include <stdio.h> #include <stdlib.h> #if defined(win) # pragma comment(lib, "glew.lib") # include "glew.h" # include "glut.h" # include "glext.h" #elif defined( APPLE ) defined(macosx) # include <GLUT/glut.h> #else # define GL_GLEXT_PROTOTYPES # include <GL/glut.h> #endif struct PositionD float x; float y; ; // struct RGB // RGB float r; float g; float b; ; struct RGBA // RGBA float r; float g; float b; float a; ;.: All.h 0

107 struct ArrayBuffer GLuint bufid; int size; //attribute ; ArrayBuffer(float* data, int s, int n); struct TextureD GLuint texid; GLint num; // ; TextureD(int tnum, void* data, int w); struct TextureD GLuint texid; GLint num; // ; TextureD(int tnum, void* data, int w, int h); struct Shader GLuint program; // Shader(const char* vsn, const char* fsn); void use(); void bindarraybuffer(const char* vname, ArrayBuffer* ap); void bindtexture(const char* vname, TextureD* tp); void bindtexture(const char* vname, TextureD* tp); void run(glenum mode, int n); ; GLuint compileprogram(glenum type, const GLchar *file); void buildprogram(const GLchar *vsfile, const GLchar *fsfile);.: All.h 0

108 void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(,); glutcreatewindow("test Window"); glclearcolor(0.,0.,0.,); // // glenable(gl_point_sprite); glenable(gl_vertex_program_point_size); sp = new Shader("shader.vert","shader.frag"); sp->use();.: initsystem() void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); RGB rgb[num_points]; rgb[0].r =.0; rgb[0].g =.0; rgb[0].b =.0; rgb[].r =.0; rgb[].g = 0.0; rgb[].b = 0.0; rgb[].r = 0.0; rgb[].g =.0; rgb[].b = 0.0; ArrayBuffer ab((float*)rgb,,num_points); sp->bindarraybuffer("in_color",&ab); // gllinewidth(0.0);.: initdata() 0

109 void display(void) glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points);.: display() int main(int argc, char *argv[]) initsystem(argc,argv); initdata(); glutdisplayfunc(display); glutmainloop(); return 0;.: main() #version 0 attribute vec position; attribute vec in_color; varying vec out_color; void main(void) gl_position = vec(position,0.0,.0); out_color = in_color;.: 0

110 #version 0 varying vec out_color; void main(void) gl_fragcolor = vec(out_color, 0.0);.: 0

111 GPGPU 0 GPU CUDA OpenCL RGBA GL LINEAR GL NEAREST RGBA D CG CUDA OpenCL GPGPU GPGPU OpenGL 0...

112 GPGPU.:. OpenGL / FBO. FBO. FBO. (a). FBO. (b) 0. RGBA. CPU. (c)

113 GPGPU.. GPGPU.. initsystem() initdata() compute() display() showresults() 0 glutdisplayfunc() glutmainloop() sp NUM POINTS width height texzp. 0.. GPGPU initsystem() initsystem(). initsystem().. glutinit() glutinitdisplaymode() glutcreatewindow("test Window"). glutinitwindowsize(width,height) width height.

114 GPGPU #include "All.h" // Shader *sp; // const int NUM_POINTS = ; // const int width = ; // const int height = ; // RWTextureD *texzp; // void initsystem() /* */ void initdata() /* */ void compute() /* GPU */ // display() void showresults() // /* */ int main() initsystem(); initdata(); compute(); showresults(); return 0;.: GPGPU

115 GPGPU void initsystem(int argc, char *argv[]) glutinit(&argc,argv); glutinitdisplaymode(glut_rgb GLUT_SINGLE); glutinitwindowsize(width,height); glutcreatewindow("test Window"); glclearcolor(0.0, 0.0, 0.0, 0.0); #if defined(win) glewinit(); #endif GLuint fb; glgenframebuffers(, &fb); glbindframebuffer(gl_framebuffer, fb); sp = new Shader("shader.vert","shader.frag"); sp->use();.: GPGPU initsystem() glclearcolor(0.0, 0.0, 0.0, 0.0) glgenframebuffers(, &fb). OpenGL. glbindframebuffer(gl FRAMEBUFFER, fb) 0 fb void glgenframebuffers(glsizei n, GLuint *ids); void glbindframebuffer( GLenum target, GLuint framebuffer);

116 GPGPU void initdata() PositionD pos[num_points]; pos[0].x = -0.; pos[0].y = -0.; pos[].x = +0.; pos[].y = +0.; pos[].x = +0.; pos[].y = -0.; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); // texzp = new RWTextureD(0,NULL,width,height);// sp->bindtexturew(texzp); //.: initdata(). use().. initdata() initdata(). 0. sp->bindarraybuffer("position",&ab) initdata().. texzp = new RWTextureD(0, NULL, width, height) texzp RWTextureD 0 0 color attachment

117 GPGPU struct RWTextureD GLuint texid; // GLint num; // ; RWTextureD(int tnum, void* data, int w, int h); // void readdata(void*, int w, int h); // GPU CPU.: RWTextureD NULL CPU GPU NULL. sp->bindtexturew(texzp) RWTextureD OpenGL RWTextureD /... glframebuffertextured(gl_framebuffer, GL_COLOR_ATTACHMENT0+num, GL_TEXTURE_D, texid, 0) texid GL TEXTUR Dnum void glframebuffertextured(glenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); color attachment color attachiment

118 GPGPU RWTextureD::RWTextureD(int tnum, void* data, int w, int h) num = tnum; glgentextures (, &texid); glbindtexture(gl_texture_d,texid); gltexparameteri(gl_texture_d, GL_GENERATE_MIPMAP, GL_FALSE); gltexparameteri(gl_texture_d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glteximaged(gl_texture_d, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_FLOAT, data); glframebuffertextured(gl_framebuffer, GL_COLOR_ATTACHMENT0+num, GL_TEXTURE_D, texid, 0);.: RWTextureD void RWTextureD::readData(void* data, int w, int h) glreadbuffer(gl_color_attachment0+num); glreadpixels(0, 0, w,h, GL_RGBA,GL_FLOAT,data);.: RWTextureD readdata() 0 readdata() GPU CPU readdata(). glreadbuffer(gl COLOR ATTACHMENT0+num) 0 GPU CPU num num. glreadpixels(0, 0, w,h, GL RGBA,GL FLOAT,data) data glbindframebuffer() initsystem() void glreadbuffer(glenum mode); void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data);

119 GPGPU void Shader::bindTextureR(const char* vname, RWTextureD* tp) glactivetexture(gl_texture0+(tp->num)); glbindtexture(gl_texture_d,tp->texid); GLint p = glgetuniformlocation(program, vname); if(p < 0) cerr << "textured name error: "<< vname << endl; exit(); gluniformi(p, tp->num); void Shader::bindTextureW(RWTextureD* tp) gldrawbuffer(gl_color_attachment0+(tp->num));.: Shader bindtexturer/w() void compute(void) glclear(gl_color_buffer_bit); sp->run(gl_triangles,num_points);.: compute() RWTextureD. Shader bindtexturer(). bindtexture() bindtexturew() gldrawbuffer(gl COLOR ATTACHMENT0+tp->num) 0 0 tp->num tp->num

120 GPGPU void showresults() RGBA result[height][width]; texzp->readdata(z,width,height); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) printf("(%.f,%.f) ", result[h][w].r, result[h][w].g); printf("\n");.0: showresults() #version 0 attribute vec position; void main(void) gl_position = vec(position,0.0,.0);.: GPGPU.. compute() compute().. display().. showresults() showresults().0 GPU r g b a cout printf() 0

121 GPGPU #version 0 void main(void) gl_fragcolor = gl_fragcoord;.:.. GPGPU.... gl FragCoord vec GLSL x y s t r g (x,y ) [0, width] [0, height] x = 0.,.,.,, width 0. y = 0.,.,.,, height 0. width= height= showresults() 0 void gldrawbuffer(glenum buf);

122 GPGPU (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0., 0.) (., 0.) (., 0.) (., 0.) (., 0.).: gl FragCoord x y width= height= (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0)

123 GPGPU (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (.,.) (.,.) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.0,0.0) (0.,0.) ( 0., 0.) (.,.) (.,.) (.,.) (.,.) (.,.) (0., 0.).:

124 GPGPU const int NUM_POINTS = ; void initdata() PositionD pos[num_points]; // pos[0].x = -.0; pos[0].y = -.0; // [-.0,.0] X [-.0,.0] pos[].x = +.0; pos[].y = -.0; // pos[].x = +.0; pos[].y = +.0; pos[].x = -.0; pos[].y = +.0; void compute(void) glclear(gl_color_buffer_bit); sp->run(gl_polygon,num_points); // POLYGON.: 0. [, ] [, ] GL TRIANGLES GL POLYGON.. showresults() (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,0.) (.,0.) (.,0.) (.,0.) (.,0.)

125 GPGPU (.0,.0) (.0,.0) (.0,.0) (.0,.0) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,0.) (.,0.) (.,0.) (.,0.) (.,0.) (0.,.) (0.,.) (.,.) (.,.) (.,.) (.,.) (0.,.) (0., 0.) (.,.) (., 0.) (.,.) (., 0.).:

126 GPGPU x.: 0. C x z z[i][j] = x[i][j]; GPU. x.. RWTextureD.. RWTextureD *texxp; RGBA x[height][width]; // //

127 GPGPU RWTextureD *texxp; RGBA x[height][width]; void initdata() PositionD pos[num_points]; pos[0].x = -.0; pos[0].y = -.0; pos[].x = +.0; pos[].y = -.0; pos[].x = +.0; pos[].y = +.0; pos[].x = -.0; pos[].y = +.0; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) x[h][w].r = w+h+0.; // x[h][w].g = w+h+0.; x[h][w].b = w+h+0.; x[h][w].a = w+h+0.; texxp = new RWTextureD(,x,width,height); // texzp = new RWTextureD(0,NULL,width,height); // sp->bindtexturer("tx",texxp); sp->bindtexturew(texzp); // GPU // sp->setfloat("width",width); sp->setfloat("height",height); // //.: initdata(). initdata(). x. x. texxp. unifrom tx sp->setfloat("width",width); sp->setfloat("height",height);

128 GPGPU void showresults() RGBA result[height][width]; texzp->readdata(result,width,height); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) printf("%d %d r : %.f %.f\n", w, h, x[h][w].r, result[h][w].r); printf("%d %d g : %.f %.f\n", w, h, x[h][w].g, result[h][w].g); printf("%d %d b : %.f %.f\n", w, h, x[h][w].b, result[h][w].b); printf("%d %d a : %.f %.f\n", w, h, x[h][w].a, result[h][w].a);.: showresults() unifrom width height showresults()....0 tx vec(gl FragCoord.x/width, gl FragCoord.y/height) gl FragCoord [0, width] [0, height] [0, ] [0, ]

129 GPGPU #version 0 uniform samplerd tx; uniform float width; uniform float height; void main(void) vec texcoord = vec(gl_fragcoord.x/width,gl_fragcoord.y/height); gl_fragcolor = textured(tx,texcoord);.0: 0.. showresults() 0 r : g : b : a : r : a : r : g : b : a :.00.00

130 GPGPU y x z float:alpha.: saxpy. x y z alpha z[i][j] = alpha*x[i][j]+y[i][j]; double double precision daxpy double alpha x plus y float single precision saxpy GPU saxpy 0.. GPU double GPU float 0

131 GPGPU RWTextureD *texyp; RGBA y[height][width]; float alpha = 0.; // // // saxpy. saxpy initdata() y texyp texxp texzp. GPU CPU showresults() alpha*x[h][w].r+y[h][w].r CPU GPU result[h][w].r 0... saxpy uniform ty alpha gl FragColor sapxy vec r g b a SIMD Single Instruction Multiple Data SIMD SIMD SPMD Single Program Multiple Data showresults() 0 r : g : b : a : r :.0.0 g : a : r : g : b : a : GPGPU

132 GPGPU RWTextureD *texxp; RGBA x[height][width]; RWTextureD *texyp; RGBA y[height][width]; RWTextureD *texzp; float alpha = 0.; void initdata() PositionD pos[num_points]; pos[0].x = -.0; pos[0].y = -.0; pos[].x = +.0; pos[].y = -.0; pos[].x = +.0; pos[].y = +.0; pos[].x = -.0; pos[].y = +.0; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) x[h][w].r = w+h+0.; x[h][w].g = w+h+0.; x[h][w].b = w+h+0.; x[h][w].a = w+h+0.; y[h][w].r = 0.; y[h][w].g = 0.; y[h][w].b = 0.; y[h][w].a = 0.; texxp = new RWTextureD(0,x,width,height); texyp = new RWTextureD(,y,width,height); texzp = new RWTextureD(,NULL,width,height); sp->bindtexturer("tx",texxp); sp->bindtexturer("ty",texyp); sp->bindtexturew(texzp); sp->setfloat("alpha",alpha); // // // // // // sp->setfloat("width",width); sp->setfloat("height",height);.: saxpy initdata()

133 GPGPU void showresults() RGBA result[height][width]; texzp->readdata(result,width,height); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) printf("%d %d r : %.f %.f\n", w,h, alpha*x[h][w].r+y[h][w].r, result[h][w].r); printf("%d %d g : %.f %.f\n", w,h, alpha*x[h][w].g+y[h][w].g, result[h][w].g); printf("%d %d b : %.f %.f\n", w,h, alpha*x[h][w].b+y[h][w].b, result[h][w].b); printf("%d %d a : %.f %.f\n", w,h, alpha*x[h][w].a+y[h][w].a, result[h][w].a);.: showresults() #version 0 uniform samplerd tx; uniform samplerd ty; uniform float alpha; // // uniform float width; uniform float height; void main(void) vec texcoord = vec(gl_fragcoord.x/width,gl_fragcoord.y/height); vec x = textured(tx,texcoord); vec y = textured(ty,texcoord); // gl_fragcolor = alpha*x+y; //.: sapxy

134 GPGPU

135 GPGPU. for(int k = 0; k < N; k++) x[i][j] = alpha*x[i][j]+y[i][j]; 0 OpenCL GPU OpenGL N for(int k = 0; k < N/; k++) z[i][j] = alpha*x[i][j]+y[i][j]; x[i][j] = alpha*z[i][j]+y[i][j]; // 0 x z GPU.. texxp texyp texzp z[i][j] = alpha*x[i][j]+y[i][j] x y z x[i][j] = alpha*z[i][j]+y[i][j] texxp texyp texzp z y x GPU ping pong computation

136 GPGPU texyp texxp texzp y x z float:alpha.: z[i][j] = alpha*x[i][j]+y[i][j] texyp texxp texzp y z x float:alpha.: x[i][j] = alpha*z[i][j]+y[i][j]

137 GPGPU 0.. RWTextureD *texxp; RGBA x[height][width]; RWTextureD *texyp; RGBA y[height][width]; RWTextureD *texzp; RGBA z[height][width];. saxpy initdata() sp->bindtexturer("tx",texxp); sp->bindtexturew(texzp);.. compute(). for(int n = 0; n < LOOPNUM/; n++)... 0 saxpy sp->bindtexturer("tx",texxp); sp->bindtexturew(texzp); glclear(gl_color_buffer_bit); sp->run(gl_polygon,num_points);. sp->bindtexturer("tx",texzp); sp->bindtexturew(texxp); glclear(gl_color_buffer_bit); sp->run(gl_polygon,num_points); 0.. GPU CPU showresults() z result width height

138 GPGPU RWTextureD *texxp; RGBA x[height][width]; RWTextureD *texyp; RGBA y[height][width]; RWTextureD *texzp; float alpha = 0.; void initdata() PositionD pos[num_points]; pos[0].x = -.0; pos[0].y = -.0; pos[].x = +.0; pos[].y = -.0; pos[].x = +.0; pos[].y = +.0; pos[].x = -.0; pos[].y = +.0; ArrayBuffer ab((float*)pos,,num_points); sp->bindarraybuffer("position",&ab); for(int h = height-; h >= 0; h--) for(int w = 0; w < width; w++) x[h][w].r = w+h+0.; x[h][w].g = w+h+0.; x[h][w].b = w+h+0.; x[h][w].a = w+h+0.; y[h][w].r = 0.; y[h][w].g = 0.; y[h][w].b = 0.; y[h][w].a = 0.; texxp = new RWTextureD(0,x,width,height); texyp = new RWTextureD(,y,width,height); texzp = new RWTextureD(,NULL,width,height); // sp->bindtexturer("tx",texxp); compute( sp->bindtexturer("ty",texyp); // sp->bindtexturew(texzp); compute( sp->setfloat("alpha",alpha); sp->setfloat("width",width); sp->setfloat("height",height);.: initdata().

139 GPGPU #define LOOPNUM 00 void compute(void) for(int n = 0; n < LOOPNUM/; n++) sp->bindtexturer("tx",texxp); sp->bindtexturew(texzp); glclear(gl_color_buffer_bit); sp->run(gl_polygon,num_points); // initdata() // initdata() sp->bindtexturer("tx",texzp); sp->bindtexturew(texxp); glclear(gl_color_buffer_bit); sp->run(gl_polygon,num_points); // texxp texzp // texxp texzp.: GPGPU compute().. PC GPU CPU GPGPU GPU CPU.0 clock() CLOCKS PER SEC clock() clock() CLOCKS PER SEC GFLOPS N(W, H, L) N(W, H, L) = W H L (.) time.h> clock t clock tbit

第3章 OpenGL の基礎

第3章 OpenGL の基礎 3 OpenGL April 20, 2012 1 / 23 31 ( ) OpenGL OpenGL 2 / 23 32 OpenGL OpenGL OpenGL (Open Graphics Library) Silicon Graphics, Inc 2 3 API (Application Program Interface) [4] UNIX OS Windows Macintosh CAD

More information

第3章 OpenGL の基礎

第3章 OpenGL の基礎 3 OpenGL April 11, 2017 1 / 28 3.1 ( ) OpenGL OpenGL 2 / 28 3.2 OpenGL OpenGL OpenGL (Open Graphics Library) Silicon Graphics, Inc. 2 3 API (Application Program Interface) [4] UNIX OS Windows Macintosh

More information

Microsoft Word - ggbook.docx

Microsoft Word - ggbook.docx 62 4GPU (Graphics Processing Unit) 4.1 4.1.1 63 63 ( 64) " () " " " 64 63 4.1.2 () GPU (Graphics Procssing Unit) (Transform) (Lighting ) T & L (Transform and Lighting) " CG 4 4 4 4 () 4 4 4 4 4 4 4 16

More information

第7章 レンダリング

第7章 レンダリング 7 April 11, 2017 1 / 59 7.1 ( ) CG 3 ( ) 2 / 59 7.2 7.2.1 ( ) 3 (rendering) 1 / (hidden line/surface calculation) a (outer normal algorithm) b Z (Z-buffer algorithm) c (scan-line algorithm) 2 (shading)

More information

第7章 レンダリング

第7章 レンダリング 7 May 18, 2012 1 / 60 71 ( ) CG 3 ( ) 2 / 60 72 71 ( ) 3 (rendering) 1 / (hidden line/surface calculation) a (outer normal algorithm) b Z (Z-buffer algorithm) c (scan-line algorithm) 2 (shading) a (flat

More information

Kageyama (Kobe Univ.) / 36

Kageyama (Kobe Univ.) / 36 DrawArrays DrawElements 05 1 2015.05.19 Kageyama (Kobe Univ.) 2015.05.19 1 / 36 Kageyama (Kobe Univ.) 2015.05.19 2 / 36 Kageyama (Kobe Univ.) 2015.05.19 3 / 36 Web アプリ HTML + CSS + JavaScript + シェーダソースコード

More information

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix()

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix() 1 20 (2) OpenGL+GUI(GLUI) 3DCG TA 2008 10 27 1 OpenGL OpenGL GUI GLUI 1.1 http://www.cyber.t.u-tokyo.ac.jp/~kuni/enshu2008/ 1.2 TA 1.3 2008/12/4( ) EyeToy 2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut

More information

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t 1 22 (2) OpenGL+GUI(GLUI) 3DCG TA 2010 10 18 1 OpenGL OpenGL GUI GLUI 1.1 http://www.cyber.t.u-tokyo.ac.jp/~kuni/enshu2010/ 1.2 TA 1.3 2010/12/6( ) USB 2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height

More information

DrawArrays DrawElements References Kageyama (Kobe Univ.) Visualization / 34

DrawArrays DrawElements References Kageyama (Kobe Univ.) Visualization / 34 WebGL *1 DrawArrays DrawElements 2013.05.14 *1 X021 2013 LR301 Kageyama (Kobe Univ.) Visualization 2013.05.14 1 / 34 DrawArrays DrawElements References Kageyama (Kobe Univ.) Visualization 2013.05.14 2

More information

WebGL Safari WebGL WebGL Safari Kageyama (Kobe Univ.) / 5

WebGL Safari WebGL WebGL   Safari Kageyama (Kobe Univ.) / 5 04 1 2015.05.12 Kageyama (Kobe Univ.) 2015.05.12 1 / 55 WebGL Safari WebGL WebGL http://www.khronos.org/webgl/ http://www.khronos.org/webgl/wiki/demo_repository Safari Kageyama (Kobe Univ.) 2015.05.12

More information

WebGL X LR301 Kageyama (Kobe Univ.) Visualization / 45

WebGL X LR301 Kageyama (Kobe Univ.) Visualization / 45 2014.05.13 X021 2014 LR301 Kageyama (Kobe Univ.) Visualization 2014.05.13 1 / 45 Kageyama (Kobe Univ.) Visualization 2014.05.13 2 / 45 Kageyama (Kobe Univ.) Visualization 2014.05.13 3 / 45 Web アプリ HTML

More information

/*p7-1-1*/

/*p7-1-1*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 /* e8.c Copyright (c) 2003 by T. HAYASHI and

More information

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h> 2007 12 5 1 2 2.1 ( ) 1 1: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define H WIN 400 // 8 #define W WIN 300 // 9

More information

untitled

untitled 2004/12/21 2/2 (11/16) DT-MRI (11/30) /OpenGL 12/7 12/14 (12/21) 1/11 (1/18) OpenGL ~ ~ OpenGL Silicon Graphics, OpenGL ~ ~ OpenGL OpenGL Utility Library (GLU) OpenGL. OpenGL. OpenGL Utility Toolkit (GLUT)

More information

libaux.dvi

libaux.dvi AUX OpenGL 1 OpenGL (AUX libaux.a) OpenGL Programming Guide () OpenGL 1 OpenGL OS (API) OS OS OS OpenGL Windows Windows X X OpenGL Programming Guide AUX toolkit AUX OS OpenGL SGI OpenGL OS OpenGL AUX Windows

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

WebGL References Kageyama (Kobe Univ.) Visualization 2013.05.07 *4 2 / 54

WebGL References Kageyama (Kobe Univ.) Visualization 2013.05.07 *4 2 / 54 WebGL *1 2013.05.07 *2 *1 X021 2013 LR301 *2 05/08: Kageyama (Kobe Univ.) Visualization 2013.05.07 *3 1 / 54 WebGL References Kageyama (Kobe Univ.) Visualization 2013.05.07 *4 2 / 54 Chrome Firefox http://www.khronos.org/webgl/wiki/demo_repository

More information

演算増幅器

演算増幅器 コンピュータグラフィックス 2 前回は GLUT を使った簡単な 2 次元グラフィックスについて習った 今週は以下の項目について 補足していく イベント駆動型プログラムの動作について コンピュータグラフィックスの座標系 イベント駆動型プログラム従来のプログラムとの違いこれまでに学習してきたプログラムは上から下に順次実行され 条件分岐や繰り返し処理によって プログラムの流れ (flow: フロー )

More information

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta 1 1. 1 #include 2 #include 3 #include 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 static bool KeyDownON = false; // 8 static bool KeyLeftON

More information

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout << C++ C C++ 1 C++ C++ C C++ C C++? C C++ C *.c *.cpp C cpp VC C++ 2 C++ C++ C++ [1], C++,,1999 [2],,,2001 [3], ( )( ),,2001 [4] B.W. /D.M.,, C,,1989 C Web [5], http://kumei.ne.jp/c_lang/ 3 Hello World Hello

More information

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E 8 9 7 6 4 2 3 5 1 j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E a n 1 H = ae l j, j=1 l j = x j+1 x j, x n x 1 = n 1 j=1 l j, l j = ±l l > 0) n 1 H = ϵ l j, j=1 ϵ e x x

More information

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber(); : : :0757230G :2008/07/18 2008/08/17 1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include class Number Number(); // ~Number(); // void setnumber(float n); float getnumber(); private: float num; ;

More information

WebGL OpenGL GLSL Kageyama (Kobe Univ.) Visualization / 57

WebGL OpenGL GLSL Kageyama (Kobe Univ.) Visualization / 57 WebGL 2014.04.15 X021 2014 3 1F Kageyama (Kobe Univ.) Visualization 2014.04.15 1 / 57 WebGL OpenGL GLSL Kageyama (Kobe Univ.) Visualization 2014.04.15 2 / 57 WebGL Kageyama (Kobe Univ.) Visualization 2014.04.15

More information

ゲームグラフィックス特論

ゲームグラフィックス特論 ゲームグラフィックス特論 第 13 回遅延レンダリング 2 Render To Texture テクスチャにレンダリング 3 レンダリング結果を素材として利用する 映り込みや屈折などの光学的効果 1. 視点を変更してレンダリングする 2. レンダリング結果をテクスチャとしてマッピングする このレンダリング結果は直接には画面に表示されない 素材を作成するために画面表示を行わずにレンダリングする オフスクリーンレンダリング

More information

2 T ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy ( ) ( ) ( ) ( ) u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a

2 T ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy ( ) ( ) ( ) ( ) u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a 2 T140073 1 2 ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a cos θ, v = v 0 + b tan θ π 2 < θ < π 2 u = u 0 + 2pt, v = v 0 + pt

More information

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - > 1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - > 8 (240 O p e n C V ) 9 opencv_core240d.lib 10 opencv_imgproc240d.lib

More information

C B

C B C 095707B 2010 6 8 1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2..............................................

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

(Version: 2017/4/18) Intel CPU 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU do

(Version: 2017/4/18) Intel CPU 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU do (Version: 2017/4/18) Intel CPU (kashi@waseda.jp) 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU double 8087 FPU (floating point number processing unit)

More information

演算増幅器

演算増幅器 スペースインベーダーもどき 1000 行プログラムの参考として スペースインベーダーもどきのプログラムを配布する いくつか習って いないものもあるので 補足の説明を加えていく 文字列の描画 文字の描画は glutbitmapcharacter() を用いる これは以下のようにして利用する int i; char *str = "Display String"; glcolor3f(0.0, 0.0,

More information

OpenGL GLSL References Kageyama (Kobe Univ.) Visualization / 58

OpenGL GLSL References Kageyama (Kobe Univ.) Visualization / 58 WebGL *1 2013.04.23 *1 X021 2013 LR301 Kageyama (Kobe Univ.) Visualization 2013.04.23 1 / 58 OpenGL GLSL References Kageyama (Kobe Univ.) Visualization 2013.04.23 2 / 58 Kageyama (Kobe Univ.) Visualization

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

07-二村幸孝・出口大輔.indd

07-二村幸孝・出口大輔.indd GPU Graphics Processing Units HPC High Performance Computing GPU GPGPU General-Purpose computation on GPU CPU GPU GPU *1 Intel Quad-Core Xeon E5472 3.0 GHz 2 6 MB L2 cache 1600 MHz FSB 80 GFlops 1 nvidia

More information

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D II 8 2003 11 12 1 6 ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 Daisuke 8 =>. 73 Daisuke 35 Hiroshi 64 Ichiro 87 Junko

More information

WebGL Safari WebGL Kageyama (Kobe Univ.) Visualization / 55

WebGL Safari WebGL   Kageyama (Kobe Univ.) Visualization / 55 WebGL WebGL 2014.04.22 X021 2014 Kageyama (Kobe Univ.) Visualization 2014.04.22 1 / 55 WebGL Safari WebGL http://bit.ly/1qxgljb Kageyama (Kobe Univ.) Visualization 2014.04.22 2 / 55 Kageyama (Kobe Univ.)

More information

OpenGL & GLUTの基本関数の説明

OpenGL & GLUTの基本関数の説明 コンピュータグラフィックス S 演習資料 OpenGL & GLUT の基本関数の説明 1. OpenGL & GLUT 2. GLUT 2.1. GLUT void glutinit( int argc, char ** argv ); glut void glutinitdysplaymode( unsigned int mode ); mode void glutinitwindowsize(

More information

2 : 2008/12/ /01/ G :

2 : 2008/12/ /01/ G : 2 : 2008/12/08 2008/01/16 075730G : 1 project draw main.cpp 1 draw main.cpp /* * main.cpp * draw * * Created by C-T on 08/12/08. * Copyright 2008 MyCompanyName. All rights reserved. * */ #include

More information

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena $ pwd /home1/t0/t0903 / / /home1/t0/t0903 / / /home1/t0/t0903 / /... ~ $ ls $ ls -a $ ls -l $ ls -l -a $ ls -la $ ls -F $ ls $ cd $ cd $ pwd $ cat

More information

準備 計算結果を可視化するために OpenGL を 利用する. 2

準備 計算結果を可視化するために OpenGL を 利用する. 2 2. 2 次元粒子法シミュレーション (+ 少しだけ OpenGL) 茨城大学工学部 教授乾正知 準備 計算結果を可視化するために OpenGL を 利用する. 2 OpenGL 3 次元コンピュータグラフィックス用の標準的なライブラリ. 特に CAD やアート, アニメーション分野 ( ゲーム以外の分野 ) で広く利用されている. OpenGL は仕様がオープンに決められており, 企業から独立した団体が仕様を管理している.

More information

(4) モデルの消去 mqodeletemodel( model ); (5) 終了処理 ( プログラム終了時にやってください ) mqocleanup(); 3. 使い方 (2) 連番ファイルを読み込んで表示する場合 (1) 初期化 (ARToolKit の場合,argInit() の後に使用 )

(4) モデルの消去 mqodeletemodel( model ); (5) 終了処理 ( プログラム終了時にやってください ) mqocleanup(); 3. 使い方 (2) 連番ファイルを読み込んで表示する場合 (1) 初期化 (ARToolKit の場合,argInit() の後に使用 ) GLMetaseq.h の中身 0810960080 渡部修平 メタセコイアで作成した 3D モデルを OpenGL で表示させるためには, 工学ナビ (http://kougaku-navi.net/artoolkit.html) が公開している C/C++ 用のライブラリ GLMetaseq があります 作成しているプログラムのプロジェクトに GLMetaseq.h と GLMetaseq.c

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1 I117 II I117 PROGRAMMING PRACTICE II 2 MEMORY MANAGEMENT 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp / SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming

More information

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程 3. 3D ビューイング 1. 3Dグラフィックス処理の一般過程 2. 射影と射影変換 3. ビューボリュームとクリッピング 4. 陰面処理とデプスバッファ 5. ビューポート変換 6. 3Dグラフィックスを描く 7. モデルビュー変換 3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程 3D グラフィックス処理の一般過程 1. モデリング変換 座標系の異なる複数のオブジェクトを仮想世界に配置し,

More information

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0) E-mail: takio-kurita@aist.go.jp 1 ( ) CPU ( ) 2 1. a f(a) =(a 1.0) 2 (1) a ( ) 1(a) f(a) a (1) a f(a) a =2(a 1.0) (2) 2 0 a f(a) a =2(a 1.0) = 0 (3) 1 9 8 7 (x-1.0)*(x-1.0) 6 4 2.0*(x-1.0) 6 2 5 4 0 3-2

More information

PowerPoint Presentation

PowerPoint Presentation 8-1 8. テクスチャマッピング 8.1. テクスチャマッピングの原理 狭義には, 図のように, 与えられた画像を物体に貼り付ける方法. マッピングには投影法, 極座標変換, パラメータマッピングなどがある (1 年 コンピュータ グラフィックス ). 広義にはバンプマッピングなども含まれる. t y s z x 8-2 8.2. テクスチャマッピングの設定方法 全体の流れ 1) 原図ビットマップデータを内部形式に変換

More information

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t 1 24 (2) 3DCG TA 2012 10 12 1 OpenGL USB (3DCG) OpenCV 1.1 http://www.cyber.t.u-tokyo.ac.jp/~tani/class/mech_enshu/ 1.2 TA 1.3 USB (2012/11/19( ),20( )) USB 2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width

More information

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved (Version: 2013/5/16) Intel CPU (kashi@waseda.jp) 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU double 8087 FPU (floating point number processing unit)

More information

2 3 OpenGL 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, IBM UNIX Linux, FreeBSD PC UNIX Windows, Mac OS API PD

2 3 OpenGL 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, IBM UNIX Linux, FreeBSD PC UNIX Windows, Mac OS API PD 1 2015 5-1 2015 6 22 1 3DCG 3DCG 3DCG OpenGL OS Linux(Ubuntu) 1.1 TA 1.2 http://www.cyber.t.u-tokyo.ac.jp/~tani/class/mech_enshu/ 2 3 OpenGL 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI)

More information

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i ) 1 f(x) a b f(x)dx = n A(x i ) (1) ix [a, b] n i A(x i ) x i 1 f(x) [a, b] n h = (b a)/n y h = (b-a)/n y = f (x) h h a a+h a+2h a+(n-1)h b x 1: 1 x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x

More information

CudaWaveField

CudaWaveField CudaWaveField 2012 3 22 2 CudaWaveField Rel 1.0.0 Rel 1.0 CudaWaveField ( cwfl) / cwfl cwfl http://www.laser.ee.kansai-u.ac.jp/wavefieldtools Note Acrobat Reader 3 I CudaWaveField 9 1 11 1.1 CudaWaveField......................

More information

program.dvi

program.dvi 2001.06.19 1 programming semi ver.1.0 2001.06.19 1 GA SA 2 A 2.1 valuename = value value name = valuename # ; Fig. 1 #-----GA parameter popsize = 200 mutation rate = 0.01 crossover rate = 1.0 generation

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

Condition DAQ condition condition 2 3 XML key value

Condition DAQ condition condition 2 3 XML key value Condition DAQ condition 2009 6 10 2009 7 2 2009 7 3 2010 8 3 1 2 2 condition 2 3 XML key value 3 4 4 4.1............................. 5 4.2...................... 5 5 6 6 Makefile 7 7 9 7.1 Condition.h.............................

More information

( CUDA CUDA CUDA CUDA ( NVIDIA CUDA I

(    CUDA CUDA CUDA CUDA (  NVIDIA CUDA I GPGPU (II) GPGPU CUDA 1 GPGPU CUDA(CUDA Unified Device Architecture) CUDA NVIDIA GPU *1 C/C++ (nvcc) CUDA NVIDIA GPU GPU CUDA CUDA 1 CUDA CUDA 2 CUDA NVIDIA GPU PC Windows Linux MaxOSX CUDA GPU CUDA NVIDIA

More information

2 2 OpenGL OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN,

2 2 OpenGL OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, 1 20 (1) OpenGL TA 2008 10 20 1 C OpenGL (3DCG) OS Linux (Open SUSE 10.3) 3DCG OpenGL GUI GLUT OpenGL GLUT GLUI USB EyeToy 1.1 1 3DCG 2 3DCG GUI 2 USB EyeToy) 10/20( ) 10/27( ) 3DCG OpenGL OpenGL+GUI(GLUI)

More information

XMPによる並列化実装2

XMPによる並列化実装2 2 3 C Fortran Exercise 1 Exercise 2 Serial init.c init.f90 XMP xmp_init.c xmp_init.f90 Serial laplace.c laplace.f90 XMP xmp_laplace.c xmp_laplace.f90 #include int a[10]; program init integer

More information

joho07-1.ppt

joho07-1.ppt 0xbffffc5c 0xbffffc60 xxxxxxxx xxxxxxxx 00001010 00000000 00000000 00000000 01100011 00000000 00000000 00000000 xxxxxxxx x y 2 func1 func2 double func1(double y) { y = y + 5.0; return y; } double func2(double*

More information

GPGPUイントロダクション

GPGPUイントロダクション 大島聡史 ( 並列計算分科会主査 東京大学情報基盤センター助教 ) GPGPU イントロダクション 1 目的 昨今注目を集めている GPGPU(GPU コンピューティング ) について紹介する GPGPU とは何か? 成り立ち 特徴 用途 ( ソフトウェアや研究例の紹介 ) 使い方 ( ライブラリ 言語 ) CUDA GPGPU における課題 2 GPGPU とは何か? GPGPU General-Purpose

More information

2 2 OpenGL ( ) OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf

2 2 OpenGL ( ) OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf 1 24 (1) OpenGL TA 2012 10 11 1 C OpenGL (3DCG) OS Linux OS 3DCG OpenGL GUI GLUT OpenGL GLUT GLUI 3DCG 3DCG 1.1 1 3DCG 3DCG GUI 2 3DCG 10/10( ) 11/11( ) 3DCG OpenGL OpenGL+GUI(GLUI) 3DCG 3DCG 1.2 TA 2

More information

1 level Level swtich ButtonPress ButtonRelease Expose Level

1 level Level swtich ButtonPress ButtonRelease Expose Level UNIX 4 2D/3D Grahpics,GUI :2-3 - 045708G 045726E 045730C 045735D 045759B 045762B 1 level1 1 11 2 12 4 13 6 14 6 2 Level2 6 21 6 211 swtich 11 212 ButtonPress 11 213 ButtonRelease 12 214 Expose 12 22 12

More information

BW BW

BW BW Induced Sorting BW 11T2042B 2015 3 23 1 1 1.1................................ 1 1.2................................... 1 2 BW 1 2.1..................................... 2 2.2 BW.................................

More information

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved (Version: 2013/7/10) Intel CPU (kashi@waseda.jp) 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU double 8087 FPU (floating point number processing unit)

More information

コンピュータグラフィックスS 演習資料

コンピュータグラフィックスS 演習資料 コンピュータグラフィックス S 演習資料 第 4 回シェーディング マッピング 九州工業大学情報工学部システム創成情報工学科講義担当 : 尾下真樹 1. 演習準備 今回の演習も 前回までの演習で作成したプログラムに続けて変更を行う まずは シェーディングの演習のため 描画処理で 回転する一つの四角すいを描画するように変更する 画面をクリア ( ピクセルデータと Z バッファの両方をクリア ) glclear(

More information

新・明解C言語 ポインタ完全攻略

新・明解C言語 ポインタ完全攻略 2 1-1 1-1 /* 1-1 */ 1 int n = 100; int *p = &n; printf(" n %d\n", n); /* n int */ printf("*&n %d\n", *&n); /* *&n int */ printf(" p %p\n", p); /* p int * */ printf("&*p %p\n", &*p); /* &*p int * */ printf("sizeof(n)

More information

file:///D|/C言語の擬似クラス.txt

file:///D|/C言語の擬似クラス.txt 愛知障害者職業能力開発校 システム設計科 修了研究発表会報告書 題名 : C 言語の擬似クラス あらまし : C 言語でクラスを作れるという噂の真偽を確かめるために思考錯誤した まえがき : VC++ や Java その他オブジェクト指向の言語にはクラスが存在して クラスはオブジェクトの設計図である 手法 : C++ のクラスを解析して C++ のクラスを作成して C 言語に翻訳する class struct

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

1 OpenCL OpenCL 1 OpenCL GPU ( ) 1 OpenCL Compute Units Elements OpenCL OpenCL SPMD (Single-Program, Multiple-Data) SPMD OpenCL work-item work-group N

1 OpenCL OpenCL 1 OpenCL GPU ( ) 1 OpenCL Compute Units Elements OpenCL OpenCL SPMD (Single-Program, Multiple-Data) SPMD OpenCL work-item work-group N GPU 1 1 2 1, 3 2, 3 (Graphics Unit: GPU) GPU GPU GPU Evaluation of GPU Computing Based on An Automatic Program Generation Technology Makoto Sugawara, 1 Katsuto Sato, 1 Kazuhiko Komatsu, 2 Hiroyuki Takizawa

More information

2 T 1 N n T n α = T 1 nt n (1) α = 1 100% OpenMP MPI OpenMP OpenMP MPI (Message Passing Interface) MPI MPICH OpenMPI 1 OpenMP MPI MPI (trivial p

2 T 1 N n T n α = T 1 nt n (1) α = 1 100% OpenMP MPI OpenMP OpenMP MPI (Message Passing Interface) MPI MPICH OpenMPI 1 OpenMP MPI MPI (trivial p 22 6 22 MPI MPI 1 1 2 2 3 MPI 3 4 7 4.1.................................. 7 4.2 ( )................................ 10 4.3 (Allreduce )................................. 12 5 14 5.1........................................

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

r3.dvi

r3.dvi 00 3 2000.6.10 0 Java ( 7 1 7 1 GSSM 1? 1 1.1 4 4a 4b / / 0 255 HTML X 0 255 16 (0,32,255 #0020FF Java xclock -bg #0020FF xclock ^C (Control C xclock 4c 1 import java.applet.applet; import java.awt.*;

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

1 GPU GPGPU GPU CPU 2 GPU 2007 NVIDIA GPGPU CUDA[3] GPGPU CUDA GPGPU CUDA GPGPU GPU GPU GPU Graphics Processing Unit LSI LSI CPU ( ) DRAM GPU LSI GPU

1 GPU GPGPU GPU CPU 2 GPU 2007 NVIDIA GPGPU CUDA[3] GPGPU CUDA GPGPU CUDA GPGPU GPU GPU GPU Graphics Processing Unit LSI LSI CPU ( ) DRAM GPU LSI GPU GPGPU (I) GPU GPGPU 1 GPU(Graphics Processing Unit) GPU GPGPU(General-Purpose computing on GPUs) GPU GPGPU GPU ( PC ) PC PC GPU PC PC GPU GPU 2008 TSUBAME NVIDIA GPU(Tesla S1070) TOP500 29 [1] 2009 AMD

More information

Informatics 2014

Informatics 2014 C 計算機の歴史 手回し計算機 新旧のソロバン バベッジの階差機関 スパコン ENIAC (1946) パソコン 大型汎用計算機 電卓 現在のコンピュータ Input Output Device Central Processing Unit I/O CPU Memory OS (Operating System) OS Windows 78, Vista, XP Windows Mac OS X

More information

WebGL *1 DOM API *1 X LR301 Kageyama (Kobe Univ.) Visualization / 37

WebGL *1 DOM API *1 X LR301 Kageyama (Kobe Univ.) Visualization / 37 WebGL *1 DOM API 2013.05.21 *1 X021 2013 LR301 Kageyama (Kobe Univ.) Visualization 2013.05.21 1 / 37 WebGL WebGL DOM References Kageyama (Kobe Univ.) Visualization 2013.05.21 2 / 37 WebGL WebGL Kageyama

More information

謗域・ュ逕ィppt

謗域・ュ逕ィppt 情報工学 2017 年度後期第 5 回 [11 月 1 日 ] 静岡大学 工学研究科機械工学専攻ロボット 計測情報講座創造科学技術大学院情報科学専攻 三浦憲二郎 講義日程 第 6 回 11 月 8 日画像処理パート第 1 回 第 7 回 11 月 15 日 CGパート第 6 回 第 8 回 11 月 22 日 CGパート第 7 回 第 9 回 11 月 29 日 CGパート試験 講義アウトライン [11

More information

SystemC言語概論

SystemC言語概論 SystemC CPU S/W 2004/01/29 4 SystemC 1 SystemC 2.0.1 CPU S/W 3 ISS SystemC Co-Simulation 2004/01/29 4 SystemC 2 ISS SystemC Co-Simulation GenericCPU_Base ( ) GenericCPU_ISS GenericCPU_Prog GenericCPU_CoSim

More information

WinHPC ppt

WinHPC ppt MPI.NET C# 2 2009 1 20 MPI.NET MPI.NET C# MPI.NET C# MPI MPI.NET 1 1 MPI.NET C# Hello World MPI.NET.NET Framework.NET C# API C# Microsoft.NET java.net (Visual Basic.NET Visual C++) C# class Helloworld

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

8 / 0 1 i++ i 1 i-- i C !!! C 2

8 / 0 1 i++ i 1 i-- i C !!! C 2 C 2006 5 2 printf() 1 [1] 5 8 C 5 ( ) 6 (auto) (static) 7 (=) 1 8 / 0 1 i++ i 1 i-- i 1 2 2.1 C 4 5 3 13!!! C 2 2.2 C ( ) 4 1 HTML はじめ mkdir work 作業用ディレクトリーの作成 emacs hoge.c& エディターによりソースプログラム作成 gcc -o fuga

More information

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10; (STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector x; for(int i = 0; i < 10; ++i) x.push_back(i); vector STL x.push_back(i) STL

More information

Kageyama (Kobe Univ.) 2015.06.23 2 / 41

Kageyama (Kobe Univ.) 2015.06.23 2 / 41 2015 2015.06.23 Kageyama (Kobe Univ.) 2015.06.23 1 / 41 Kageyama (Kobe Univ.) 2015.06.23 2 / 41 [ 1, +1] [ 1, +1] [ 1, +1] Kageyama (Kobe Univ.) 2015.06.23 3 / 41 Kageyama (Kobe Univ.) 2015.06.23 4 / 41

More information

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO Handy Graphic for Handy Graphic Version 0.5 2008-06-09 1 Handy Graphic Handy Graphic C Handy Graphic Handy Graphic Mac OS X Handy Graphic HgDisplayer Handy Graphic HgDisplayer 2 Handy Graphic 1 Handy Graphic

More information

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1: 005 9 7 1 1.1 1 Hello World!! 5 p r i n t f ( H e l l o World!! \ n ) ; 7 return 0 ; 8 } 1: 1 [ ] Hello World!! from Akita National College of Technology. 1 : 5 p r i n t f ( H e l l o World!! \ n ) ;

More information

main.dvi

main.dvi PC 1 1 [1][2] [3][4] ( ) GPU(Graphics Processing Unit) GPU PC GPU PC ( 2 GPU ) GPU Harris Corner Detector[5] CPU ( ) ( ) CPU GPU 2 3 GPU 4 5 6 7 1 toyohiro@isc.kyutech.ac.jp 45 2 ( ) CPU ( ) ( ) () 2.1

More information

programmingII2019-v01

programmingII2019-v01 II 2019 2Q A 6/11 6/18 6/25 7/2 7/9 7/16 7/23 B 6/12 6/19 6/24 7/3 7/10 7/17 7/24 x = 0 dv(t) dt = g Z t2 t 1 dv(t) dt dt = Z t2 t 1 gdt g v(t 2 ) = v(t 1 ) + g(t 2 t 1 ) v v(t) x g(t 2 t 1 ) t 1 t 2

More information

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

[1] #include<stdio.h> main() { printf(hello, world.); return 0; } (G1) int long int float ± ± [1] #include printf("hello, world."); (G1) int -32768 32767 long int -2147483648 2147483647 float ±3.4 10 38 ±3.4 10 38 double ±1.7 10 308 ±1.7 10 308 char [2] #include int a, b, c, d,

More information

WebGL Kageyama (Kobe Univ.) Visualization / 39

WebGL Kageyama (Kobe Univ.) Visualization / 39 WebGL *1 WebGL 2013.04.30 *1 X021 2013 LR301 Kageyama (Kobe Univ.) Visualization 2013.04.30 1 / 39 WebGL Kageyama (Kobe Univ.) Visualization 2013.04.30 2 / 39 3 1 PC ID Kageyama (Kobe Univ.) Visualization

More information

Microsoft Word - C.....u.K...doc

Microsoft Word - C.....u.K...doc C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ

More information

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf (sum=%d n,sum); 2 アセンブラ (Z80) の例 ORG 100H LD B,10 SUB A LOOP: ADD A,B DEC B JR NZ,LOOP LD (SUM),A HALT ORG 200H SUM: DEFS 1 END 1 C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i

More information

Microsoft PowerPoint - GPU_computing_2013_01.pptx

Microsoft PowerPoint - GPU_computing_2013_01.pptx GPU コンピューティン No.1 導入 東京工業大学 学術国際情報センター 青木尊之 1 GPU とは 2 GPGPU (General-purpose computing on graphics processing units) GPU を画像処理以外の一般的計算に使う GPU の魅力 高性能 : ハイエンド GPU はピーク 4 TFLOPS 超 手軽さ : 普通の PC にも装着できる 低価格

More information

OpenGL Programming Course OpenGL Programming Course FAQ

OpenGL Programming Course OpenGL Programming Course FAQ OpenGL NK EXA Corporation OpenGL@dst.nk-exa.co.jp OpenGL@dst.nk-exa.co.jp OpenGL FAQ (http://www.nk-exa.co.jp/mmtech/opengledu/faq.shtml) i 1 OpenGL 1{1 1.1 OpenGL : : : : : : : : : : : : : : : : : : :

More information

comment.dvi

comment.dvi ( ) (sample1.c) (sample1.c) 2 2 Nearest Neighbor 1 (2D-class1.dat) 2 (2D-class2.dat) (2D-test.dat) 3 Nearest Neighbor Nearest Neighbor ( 1) 2 1: NN 1 (sample1.c) /* -----------------------------------------------------------------

More information

Informatics 2010.key

Informatics 2010.key http://math.sci.hiroshima-u.ac.jp/ ~ryo/lectures/informatics2010/ 1 2 C ATM etc. etc. (Personal Computer) 3 4 Input Output Device Central Processing Unit I/O CPU Memory 5 6 (CPU),,... etc. C, Java, Fortran...

More information

Microsoft Word - no15.docx

Microsoft Word - no15.docx 7. ファイルいままでは プログラムを実行したとき その結果を画面で確認していました 簡単なものならそれでもいいのですか 複雑な結果は画面で見るだけでなく ファイルに保存できればよいでしょう ここでは このファイルについて説明します 使う関数のプロトタイプは次のとおりです FILE *fopen(const char *filename, const char *mode); ファイルを読み書きできるようにする

More information

Microsoft Word - Cプログラミング演習(12)

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information