Using OpenGL with CUDA

Similar documents

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

Lecture 3. Understanding of OPenGL programming

Lectures OpenGL Introduction

Announcements OpenGL. Computer Graphics. Spring CS4815

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to OpenGL: Part 2

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Drawing Primitives. OpenGL basics

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

Programming using OpenGL: A first Introduction

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

CS 432 Interactive Computer Graphics

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

LECTURE 02 OPENGL API

Precept 2 Aleksey Boyko February 18, 2011

CS 4204 Computer Graphics

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

CSE4030 Introduction to Computer Graphics

Basic Graphics Programming

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Interaction. CSCI 480 Computer Graphics Lecture 3

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Basic Graphics Programming

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Fourier Series. Given a periodic function, x(t), (-T <t <T): + b n sin n t T. a n cos n t T. 2 a 0 + Z T. a n = 1 T. x(t) cos n t T. b n = 1 T.

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Introduction to MS Visual C/C++

OpenGL refresher. Advanced Computer Graphics 2012

GLUT Tutorial. John Tsiombikas (Nuclear / The Lab Demos) May 6, Introduction to GLUT (OpenGL Utility Toolkit)

Graphics Programming

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

COMPUTER GRAPHICS LAB # 3

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

1.2 Basic Graphics Programming

RECITATION - 1. Ceng477 Fall

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Introduction to OpenGL

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Programming with OpenGL Part 3: Three Dimensions

Interaction Computer Graphics I Lecture 3

Programming with OpenGL Part 1: Background

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Bob s Concise Introduction to Doxygen

Assignment 1. Simple Graphics program using OpenGL

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

3D computer graphics: geometric modeling of objects in the computer and rendering them

6. Make use of glviewport() to display two sine curves on the same screen, one on the

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Computer Graphics (Basic OpenGL)

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics Introduction to OpenGL

Exercise 1 Introduction to OpenGL

Computer Graphics. OpenGL

Philip Calderon CSE 520 Lab 3 Color Shader

Computer Graphics Course 2005

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

C++ - OpenGL - Setting up Visual Studio

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

2 Transformations and Homogeneous Coordinates

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.

Erik Anchondo cse 520 lab 4

C OMPUTER G RAPHICS Thursday

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Computer Graphics Primitive Attributes

Source code: #include <iostream>

Order of Transformations

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Interaction. CSCI 420 Computer Graphics Lecture 3

(21) OpenGL GUI. OpenGL GUI 1 UNIX MAGAZINE UNIX. SGI (Silicon Graphics Inc.) Windows PC GUI. UNIX Windows GUI. Java. 1 prefposition() X X

GLUT Tutorial. Keyboard

PART-I: Lab for MCS-051 (Advanced Internet Technologies)

Lecture 4 of 41. Lab 1a: OpenGL Basics

Transformation, Input and Interaction. Hanyang University

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Programming with OpenGL Part 1: Background

Transcription:

Using OpenGL with CUDA Installing OpenGL and GLUT; compiling with nvcc Basics of OpenGL and GLUT in C Interoperability between OpenGL and CUDA OpenGL = Open Graphic Library creation of 3D graphic primitives rendering through a virtual camera GLUT = OpenGL Utility Toolkit creation of a window time loop for real-time animation and rendering 1

Installing OpenGL and GLUT; compiling with nvcc installation for Windows 7-64 bits and Visual Studio 2008: download download from glut-3.7.6-bin.zip freeglut-msvc-2.8.0-1.mp.zip http://www.transmissionzero.co.uk/software/freeglut-devel/ unzip some files and install them on C: drive: glut-3.7.6-bin.zip\glut-3.7.6-bin glut32.lib C:\Program Files (x86)\microsoft Visual Studio 9.0\VC\lib\amd64 freeglut-msvc-2.8.0-1.mp.zip\freeglut\include\gl glut.h, freeglut.h, freeglut_ext.h, freeglut_std.h C:\Program Files (x86)\microsoft Visual Studio 9.0\VC\include\GL freeglut-msvc-2.8.0-1.mp.zip\freeglut\lib\x64 freeglut.lib C:\Program Files (x86)\microsoft Visual Studio 9.0\VC\lib\amd64 freeglut-msvc-2.8.0-1.mp.zip\freeglut\bin\x64 freeglut.dll C:\Windows 2

include file: #include <GL/glut.h> for both GLUT and OpenGL and GLU must be written after #include <stdio.h> and #include <stdlib.h> do not include <gl.h> and <glu.h> compilation with nvcc 3.2 for a 64-bit executable: simply add freeglut.lib in the nvcc command line instruction example: compiling P.cu call "C:\Program Files (x86)\microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin\nvcc" -O -arch sm_20 -Xcompiler -O2 P.cu freeglut.lib -o P.exe 3

Basics of OpenGL and GLUT in C window and animation loop with GLUT functions: callback functions: window callback function reshape is called each time the window's shape is modified animation loop callback function evolve is called each time GLUT is idle = update degrees of freedom request a repaint of the window callback function display is called to (re)paint the window 4

initializations inside main(int argc, char *argv[]) : start GLUT: glutinit(argc, argv); set the display mode: glutinitdisplaymode( GLUT_DOUBLE GLUT_RGB ); code value(s) combined with bitwise-or's GLUT_DOUBLE double-buffering GLUT_RGB RGBA mode set the initial window size: glutinitwindowsize(w, h); width, height set the initial window position: glutinitwindowposition(x, y); position of upper-left corner create the window: glutcreatewindow("window name"); declare reshape as the callback reshape function: glutreshapefunc(reshape); declare display as the callback display function: glutdisplayfunc(display); declare evolve as the callback idle function: glutidlefunc(evolve); enter the glut loop: glutmainloop(); we never exit from GLUT loop put glutmainloop(); at the end of main 5

callback function reshape(int w, int h) : define the window's shape and the optic of the virtual camera reshape is first called just after window creation window resized by user OpenGL recalls reshape with new size (w, h) callback function display() : display the graphic primitives (vertices...) at the end of display, swap the two buffers of the window: glutswapbuffers(); currently displayed buffer buffer that has just been updated callback function evolve() : update the values of the degrees of freedom at the end of evolve, request display to be called again: glutpostredisplay(); no arguments allowed for these callback functions (except w, h for reshape ) use C external variable(s) to access program data 6

graphic primitives and rendering with OpenGL: inside main(int argc, char *argv[]) : glclearcolor(r, g, b, a); set the clearing color inside reshape : glviewport (0, 0, w, h); glmatrixmode(gl_projection); glloadidentity(); glortho(x0, X1, Y0, Y1, Z0, Z1); window's shape optic of camera: orthographic projection (no perspective) of [X 0, X 1 ] [Y 0, Y 1 ] along Z axis (only objects inside [Z 0, Z 1 ] ) inside display : glclear(gl_color_buffer_bit); glmatrixmode(gl_modelview); glloadidentity(); clear up window with the clearing color (identity) transformation from camera's coordinate system toward absolute coordinate system create some vertices between glbegin(gl_points); and glend(); : for each vertex (x, y, z) of color (r, g, b) : glcolor3f(r, g, b); glvertex3f(x, y, z); 7

example: animation with a single vertex #include <math.h> #include <GL/glut.h> double X = 0.5, Y = 0.0, Z = 0.0, T = 0.0; void reshape(int w, int h) { glviewport (0, 0,w, h); glmatrixmode(gl_projection); glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, 0.0, 1.0); } void display(void) { glclear(gl_color_buffer_bit); glmatrixmode(gl_modelview); glloadidentity(); glbegin(gl_points); glcolor3f(1.0, 1.0, 0.0); glvertex3f(x, Y, Z); glend(); } glutswapbuffers(); void evolve(void) { X = 0.5 * cos(t); Y = 0.5 * sin(t); Z = 0; T += 0.01; } glutpostredisplay(); int main(int argc, char *argv[]) { glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB); glutinitwindowsize(200, 200); glutinitwindowposition(0, 0); glutcreatewindow("one vertex"); glclearcolor(0.0, 0.0, 0.0, 0.0); glutreshapefunc(reshape); glutdisplayfunc(display); glutidlefunc(evolve); glutmainloop(); return 0; } 8

Interoperability between OpenGL and CUDA To be developed, see Section 3.2.7 of CUDA Programming Guide set the CUDA device with cudaglsetgldevice(index); mutually exclusive from cudasetdevice(index); OpenGL data can be stored inside the CUDA card's global memory OpenGL vertices can be modified directly and in parallel from a CUDA kernel idem for textures... 9