Introduction. - C-like language for programming vertex and fragment shaders
|
|
- Malcolm Russell
- 6 years ago
- Views:
Transcription
1 Introduction to Cg Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico
2 Introduction Cg = C for graphics - C-like language for programming vertex and fragment shaders References - R. Fernando and M. Kilgard, The Cg Tutorial, Addison-Wesley - Cg Users Manual, available on-line 2
3 Cg Model 3
4 Writing Program We can write and compile shaders independently and load them as either source or assembly code - Compiler cgc cgc simple.cg flags Or use sdk Can hand optimize assembly - Tie to OpenGL or Direct X program through runtime libraries cc openglprog.c lglut lglu lgl lcg lcggl.. 4
5 Simple Vertex Shader struct C2E1v_Output float4 position : POSITION; float4 color : COLOR; }; define an output structure C2E1v_Output C2E1v_green(float2 position : POSITION) vertex C2E1v_Output OUT; location OUT.position = float4(position, 0, 1); OUT.color = float4(0, 1, 0, 1); // RGBA green } return OUT; 5
6 Vertex Shader Vertex shader must output a position Can also output other information such as a color Note use of constructor to form 4 dimensional position for output Other state information is unchanged Next example is a pass through fragment shader that does nothing 6
7 Simple Fragment Shader struct C2E2f_Output float4 color : COLOR; }; C2E2f_Output C2E2f_passthrough(float4 color : COLOR) C2E2f_Output OUT; OUT.color = color; return OUT; } 7
8 Fragment Shader Must produce a color Can also output other information Gets color as an input since the fragment program takes in the output of the rasterizer 8
9 Interfacing with OpenGL Unlike C, Cg code is platform dependent because not all GPUs have the same capabilities - Describe GPU capabilities by profiles - Compile for a profile Must interface with a Cg runtime library and OpenGL specific library Establish a Cg context, Cg variables, and links to OpenGL variables 9
10 Cg Vertex Shading Example 10
11 simple.cg // Define inputs from application. struct appin float4 Position : POSITION; float4 Normal : NORMAL; }; // Define outputs from vertex shader. struct vertout float4 HPosition : POSITION; float4 Color : COLOR; }; 11
12 simple.cg (cont) vertout main(appin IN, uniform float4x4 ModelViewProj, uniform float4x4 ModelViewIT, uniform float4 LightVec) vertout OUT; // Transform vertex position into homogenous clip-space. OUT.HPosition = mul(modelviewproj, IN.Position); // Transform normal from model-space to view-space. float3 normalvec = normalize(mul(modelviewit, IN.Normal).xyz); 12
13 simple.cg (cont) // Store normalized light vector. float3 lightvec = normalize(lightvec.xyz); // Calculate half angle vector. float3 eyevec = float3(0.0, 0.0, 1.0); float3 halfvec = normalize(lightvec + eyevec); // Calculate diffuse component. float diffuse = dot(normalvec, lightvec); // Calculate specular component. float specular = dot(normalvec, halfvec); // Use the lit function to compute lighting vector from // diffuse and specular values. float4 lighting = lit(diffuse, specular, 32); 13
14 simple.cg (cont) // Blue diffuse material float3 diffusematerial = float3(0.0, 0.0, 1.0); // White specular material float3 specularmaterial = float3(1.0, 1.0, 1.0); // Combine diffuse and specular contributions and // output final vertex color. OUT.Color.rgb = lighting.y * diffusematerial + lighting.z * specularmaterial; OUT.Color.a = 1.0; return OUT; } 14
15 Linking with OpenGL Next two examples show use of Cg runtime libraries to connect with an OpenGL program First example is from Cg user s manual Second example is from web (see link on class home page) 15
16 Cg Vertex Program void VertexProgram( in float4 position : POSITION, in float4 color : COLOR0, in float4 texcoord : TEXCOORD0, out float4 positiono : POSITION, out float4 coloro : COLOR0, out float4 texcoordo : TEXCOORD0, const uniform float4x4 ModelViewMatrix ) positiono = mul(position, ModelViewMatrix); coloro = color; texcoordo = texcoord; } 16
17 Cg Vertex Program II Program does nothing except convert position by model-view matrix to eye coordinates Passes though color and texture coordinates The uniform variable obtains its initial value from the OpenGL state - Use runtime library to connect Cg and OpenGL 17
18 Cg Fragment Program void FragmentProgram( in float4 color : COLOR0, in float4 texcoord : TEXCOORD0, out float4 coloro : COLOR0, const uniform sampler2d BaseTexture, const uniform float4 SomeColor) coloro = color * tex2d(basetexture, texcoord) + SomeColor; } 18
19 Fragment Program II Pass in color and texture coodinate - Note we can pass in multiple colors from OpenGL Second color (SomeColor) and sampler BaseTexture are passed in from OpenGL program - The sampler is set up in the OpenGL code - Describes a texture Output color is computed by sampling the texture with the passed in (interpolated) texture coordinate Now let s look at OpenGL program 19
20 #include <cg/cg.h> #include <cg/cggl.h> OpenGL Program float* vertexpositions; // Initialized somewhere else float* vertexcolors; // Initialized somewhere else float* vertextexcoords; // Initialized somewhere else GLuint texture; // Initialized somewhere else float constantcolor[]; // Initialized somewhere else 20
21 OpenGL Program (cont) // Cg variables CGcontext context; CGprogram vertexprogram, fragmentprogram; CGprofile vertexprofile, fragmentprofile; CGparameter position, color, texcoord, basetexture, somecolor, modelviewmatrix; 21
22 OpenGL Program (cont) // Called at initialization void CgGLInit() // Create context context = cgcreatecontext(); // Initialize profiles and compiler options vertexprofile = cgglgetlatestprofile(cg_gl_vertex); cgglsetoptimaloptions(vertexprofile); 22
23 OpenGL Program (cont) fragmentprofile = cgglgetlatestprofile(cg_gl_fragment); cgglsetoptimaloptions(fragmentprofile); // Create the vertex program vertexprogram = cgcreateprogramfromfile( context, CG_SOURCE, "VertexProgram.cg", vertexprofile, "VertexProgram", 0); 23
24 OpenGL Program (cont) // Load the program cgglloadprogram(vertexprogram); // Create the fragment program fragmentprogram = cgcreateprogramfromfile( context, CG_SOURCE, "FragmentProgram.cg", fragmentprofile, "FragmentProgram", 0); 24
25 OpenGLProgram (cont) // Load the program cgglloadprogram(fragmentprogram); // Grab some parameters. position = cggetnamedparameter(vertexprogram, "position"); color = cggetnamedparameter(vertexprogram, "color"); texcoord = cggetnamedparameter(vertexprogram, "texcoord"); 25
26 OpenGL Program (cont) // match Cg and OpenGL parameters // set means OpenGL Cg // get means Cg OpenGL modelviewmatrix = cggetnamedparameter(vertexprogram, "ModelViewMatrix"); basetexture = cggetnamedparameter(fragmentprogram, "BaseTexture"); somecolor = cggetnamedparameter(fragmentprogram, "SomeColor"); 26
27 OpenGL Program (cont) // Set parameters that don't change: // They can be set only once because of parameter shadowing. cgglsettextureparameter(basetexture, texture); cgglsetparameter4fv(somecolor, constantcolor); } // Called to render the scene void Display() // Set the varying parameters cgglenableclientstate(position); cgglsetparameterpointer(position, 3, GL_FLOAT, 0, vertexpositions); cgglenableclientstate(color); 27
28 OpenGL Program (cont) cgglsetparameterpointer(color, 1, GL_FLOAT, 0, vertexcolors); cgglenableclientstate(texcoord); cgglsetparameterpointer(texcoord, 2, GL_FLOAT, 0, vertextexcoords); // Set the uniform parameters that change every frame cgglsetstatematrixparameter(modelviewmatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); // Enable the profiles cgglenableprofile(vertexprofile); cgglenableprofile(fragmentprofile); 28
29 OpenGL Program (cont) // Bind the programs cgglbindprogram(vertexprogram); cgglbindprogram(fragmentprogram); // Enable texture cgglenabletextureparameter(basetexture); // Draw scene //... // Disable texture cggldisabletextureparameter(basetexture); // Disable the profiles cggldisableprofile(vertexprofile); cggldisableprofile(fragmentprofile); 29
30 OpenGL Program (cont) // Set the varying parameters cggldisableclientstate(position); cggldisableclientstate(color); cggldisableclientstate(texcoord); } // Called before application shuts down void CgShutdown() // This frees any runtime resource. cgdestroycontext(context); } 30
31 Fragment Program struct appdata float4 position : POSITION; float4 color : COLOR0; float3 wave : COLOR1; }; struct vfconn float4 HPos : POSITION; float4 Col0 : COLOR0; }; 31
32 Fragment Program (cont) vfconn main(appdata IN, uniform float4x4 ModelViewProj) vfconn OUT; // Variable to handle our output from the vertex // shader (goes to a fragment shader if available). 32
33 Fragment Program (cont) } // Change The Y Position Of The Vertex Based On Sine Waves IN.position.y = ( sin(in.wave.x + (IN.position.x / 5.0) ) + sin(in.wave.x + (IN.position.z / 4.0) ) ) * 2.5f; // Transform The Vertex Position Into Homogenous Clip- Space (Required) OUT.HPos = mul(modelviewproj, IN.position); // Set The Color To The Value Specified In IN.color OUT.Col0.xyz = IN.color.xyz; return OUT; 33
34 GLUT Program #include <GL/gl.h> #include <GL/glu.h> #include <Cg/cg.h> #include <Cg/cgGL.h> #include <stdlib.h> #include <stdio.h> #include <GL/glut.h> // User Defined Variables #define SIZE 64 // Defines The Size Of The X/Z Axis Of The Mesh 34
35 GLUT Program (cont) bool cg_enable = true, sp; // Toggle Cg Program On / Off, Space Pressed? GLfloat mesh[size][size][3]; // Our Static Mesh GLfloat wave_movement = 0.0f; // Our Variable To Move The Waves Across The Mesh CGcontext cgcontext; // A Context To Hold Our Cg Program(s) CGprogram cgprogram; // Our Cg Vertex Program CGprofile cgvertexprofile; // The Profile To Use For Our Vertex Shader CGparameter position, color, modelviewmatrix, wave; // The Parameters Needed For Our Shader 35
36 GLUT Program (cont) bool Initialize () // Any GL Init Code & User Initialization Goes Here glclearcolor (0.0f, 0.0f, 0.0f, 0.5f); glcleardepth (1.0f); gldepthfunc (GL_LEQUAL); glenable (GL_DEPTH_TEST); glshademodel (GL_SMOOTH); glhint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 36
37 GLUT example (cont) // set up mesh for (int x = 0; x < SIZE; x++) for (int z = 0; z < SIZE; z++) mesh[x][z][0] = (float) (SIZE / 2) - x; // We Want To Center Our Mesh Around The Origin mesh[x][z][1] = 0.0f; // Set The Y Values For All Points To 0 mesh[x][z][2] = (float) (SIZE / 2) - z; // We Want To Center Our Mesh Around The Origin } } 37
38 GLUT example (cont) // Setup Cg cgcontext = cgcreatecontext(); // Create A New Context For Our Cg Program(s) // Validate Our Context Generation Was Successful if (cgcontext == 0) fprintf(stderr, "Failed To Create Cg Context\n"); exit(-1); // We Cannot Continue } 38
39 GLUT Example (cont) cgvertexprofile = cgglgetlatestprofile(cg_gl_vertex); // Get The Latest GL Vertex Profile // Validate Our Profile Determination Was Successful if (cgvertexprofile == CG_PROFILE_UNKNOWN) fprintf(stderr, "Invalid profile type\n"); exit(-1); // We Cannot Continue } cgglsetoptimaloptions(cgvertexprofile); // Set The Current Profile 39
40 GLUT examples (cont) // Load And Compile The Vertex Shader From File cgprogram = cgcreateprogramfromfile(cgcontext, CG_SOURCE, "./Cg/Wave.cg", cgvertexprofile, "main", 0); if (cgprogram == 0) CGerror Error = cggeterror(); } fprintf(stderr,"%s \n",cggeterrorstring(error)); exit(-1); 40
41 GLUT Example (cont) cgglloadprogram(cgprogram); // Get Handles To Each Of Our Parameters So That // We Can Change Them At Will Within Our Code position = cggetnamedparameter(cgprogram, "IN.position"); color = cggetnamedparameter(cgprogram, "IN.color"); wave = cggetnamedparameter(cgprogram, "IN.wave"); modelviewmatrix = cggetnamedparameter(cgprogram, "ModelViewProj"); } return true; 41
42 GLUT Example (cont) void Deinitialize (void) cgdestroycontext(cgcontext); } void Update (int key,int x,int y) if ( key==27 ) Deinitialize(); exit(0); }; 42
43 GLUT example (cont) // if (g_keys->keydown [VK_F1]) // Is F1 Being Pressed? // ToggleFullscreen (g_window); // Toggle Fullscreen Mode if ( key==' ' ) sp=!sp; cg_enable=!cg_enable; }; } glutpostredisplay(); 43
44 GLUT example (cont) void Draw (void) glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glloadidentity (); glulookat(0.0f, 25.0f, -45.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0); // Set The Modelview Matrix Of Our Shader To Our OpenGL Modelview Matrix cgglsetstatematrixparameter(modelviewmatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 44
45 GLUT Example (cont) if (cg_enable) cgglenableprofile(cgvertexprofile); // Enable Our Vertex Shader Profile // Bind Our Vertex Program To The Current State cgglbindprogram(cgprogram); } // Set The Drawing Color To Light Green //(Can Be Changed By Shader, Etc...) cgglsetparameter4f(color, 0.5f, 1.0f, 0.5f, 1.0f); 45
46 GLUT Example (cont) for (int x = 0; x < SIZE - 1; x++) // Start Drawing Our Mesh // Draw A Triangle Strip For Each Column Of Our Mesh glbegin(gl_triangle_strip); for (int z = 0; z < SIZE - 1; z++) // Set The Wave Parameter Of Our Shader To The // Incremented Wave Value From Our Main Program cgglsetparameter3f(wave, wave_movement, 1.0f, 1.0f); glvertex3f(mesh[x][z][0], mesh[x][z][1], mesh[x][z][2]); glvertex3f(mesh[x+1][z][0], mesh[x+1][z][1], mesh[x+1][z][2]); wave_movement += f; } glend(); } 46
47 GLUT example (cont) if (cg_enable) cggldisableprofile(cgvertexprofile); // Disable Our Vertex Profile } glflush (); Flush The GL Rendering Pipeline glutswapbuffers(); // 47
48 callbacks void ReshapeGL (int width, int height) glviewport (0, 0, (GLsizei)(width), (GLsizei)(height)); glmatrixmode (GL_PROJECTION); glloadidentity (); gluperspective (45.0f, (GLfloat)(width)/(GLfloat)(height), 0.1f, 100.0f); glmatrixmode (GL_MODELVIEW); glloadidentity (); glutpostredisplay(); } 48
49 callbacks void Key(unsigned char key,int x,int y) Update(key,x,y); return ; }; void OnIdle() glutpostredisplay(); }; 49
50 main() int main( int argc, char *argv[] ) glutinit( &argc, argv ); glutinitwindowposition( 0, 0 ); glutinitwindowsize( 640, 480 ); glutinitdisplaymode( GLUT_RGB GLUT_DOUBLE GLUT_DEPTH ); glutcreatewindow(argv[0]); glutreshapefunc( ReshapeGL ); glutkeyboardfunc( Key ); glutspecialfunc( Update ); glutdisplayfunc( Draw ); glutidlefunc( OnIdle ); Initialize(); glutmainloop(); } 50
OpenGL refresher. Advanced Computer Graphics 2012
Advanced Computer Graphics 2012 What you will see today Outline General OpenGL introduction Setting up: GLUT and GLEW Elementary rendering Transformations in OpenGL Texture mapping Programmable shading
More informationComputer Graphics. Bing-Yu Chen National Taiwan University
Computer Graphics Bing-Yu Chen National Taiwan University Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering
More informationLecture 4 of 41. Lab 1a: OpenGL Basics
Lab 1a: OpenGL Basics William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: http://snipurl.com/1y5gc Course web site: http://www.kddresearch.org/courses/cis636 Instructor
More informationERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL
ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO SANTA BARBARA SANTA CRUZ EECS 104 Fundamentals of Computer Graphics OpenGL Slides courtesy of Dave Shreine, Ed Angel and Vicki Shreiner
More informationIntroduction to Computer Graphics with OpenGL/GLUT
Introduction to Computer Graphics with OpenGL/GLUT What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) High-quality color images composed of geometric and image
More informationUNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M
UNIT 7 LIGHTING AND SHADING 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M Ans: Phong developed a simple model that can be computed rapidly It considers three
More informationCG Programming: 3D Texturing
CG Programming: 3D Texturing 3D texturing is used as image based rendering Applications 3D texture mapping for complicate geometric objects It generates highly natural visual effects in which objects appear
More informationComputer graphics MN1
Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? How do I use it? Rendering pipeline Points, vertices, lines,, polygons Matrices and transformations Lighting and shading Code
More informationOpenGL/GLUT Intro. Week 1, Fri Jan 12
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week 1, Fri Jan 12 http://www.ugrad.cs.ubc.ca/~cs314/vjan2007 News Labs start next week Reminder:
More informationBasic Graphics Programming
15-462 Computer Graphics I Lecture 2 Basic Graphics Programming Graphics Pipeline OpenGL API Primitives: Lines, Polygons Attributes: Color Example January 17, 2002 [Angel Ch. 2] Frank Pfenning Carnegie
More informationRECITATION - 1. Ceng477 Fall
RECITATION - 1 Ceng477 Fall 2007-2008 2/ 53 Agenda General rules for the course General info on the libraries GLUT OpenGL GLUI Details about GLUT Functions Probably we will not cover this part 3/ 53 General
More informationC OMPUTER G RAPHICS Thursday
C OMPUTER G RAPHICS 2017.04.27 Thursday Professor s original PPT http://calab.hanyang.ac.kr/ Courses Computer Graphics practice3.pdf TA s current PPT not uploaded yet GRAPHICS PIPELINE What is Graphics
More informationBooks, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D
Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D CS334 Spring 2012 Daniel G. Aliaga Department of Computer Science Purdue University Computer Graphics Pipeline Geometric Primitives
More informationLecture 2 2D transformations Introduction to OpenGL
Lecture 2 2D transformations Introduction to OpenGL OpenGL where it fits what it contains how you work with it OpenGL parts: GL = Graphics Library (core lib) GLU = GL Utilities (always present) GLX, AGL,
More informationPrecept 2 Aleksey Boyko February 18, 2011
Precept 2 Aleksey Boyko February 18, 2011 Getting started Initialization Drawing Transformations Cameras Animation Input Keyboard Mouse Joystick? Textures Lights Programmable pipeline elements (shaders)
More informationComputer Graphics 1 Computer Graphics 1
Projects: an example Developed by Nate Robbins Shapes Tutorial What is OpenGL? Graphics rendering API high-quality color images composed of geometric and image primitives window system independent operating
More informationVR-programming tools (procedural) More VRML later in this course! (declarative)
Realtime 3D Computer Graphics & Virtual Reality OpenGL Introduction VR-programming Input and display devices are the main hardware interface to users Immersion embeds users through the generation of live-like
More informationProgramming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall
Programming with OpenGL Part 2: Complete Programs 91.427 Computer Graphics I, Fall 2008 1 1 Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D
More informationOpenGL for dummies hello.c #include int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition
More informationOpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders
OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders Prateek Shrivastava CS12S008 shrvstv@cse.iitm.ac.in 1 GLSL Data types Scalar types: float, int, bool Vector
More informationTo Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics
More informationBooks, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt
Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt CS334 Fall 2015 Daniel G. Aliaga Department of Computer Science Purdue University Books (and by now means complete ) Interactive Computer
More information2 Transformations and Homogeneous Coordinates
Brief solutions to Exam in Computer Graphics Time and place: 08:00 3:00 Tuesday March 7, 2009, Gimogatan 4, sal Grades TD388: 3: 20pts; 4: 26pts; 5: 34pts. Glossary API Application Programmer s Interface.
More informationGL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW
OpenGL Syntax Functions have prefix gl and initial capital letters for each word glclearcolor(), glenable(), glpushmatrix() glu for GLU functions glulookat(), gluperspective() constants begin with GL_,
More informationLectures OpenGL Introduction
Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 What is
More informationIntroduction to OpenGL Week 1
CS 432/680 INTERACTIVE COMPUTER GRAPHICS Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico Objectives
More informationObjectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1
CS 432/680 INTERACTIVE COMPUTER GRAPHICS Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Objectives Learn the basic design of a graphics system Introduce graphics
More informationProgramming using OpenGL: A first Introduction
Programming using OpenGL: A first Introduction CMPT 361 Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller 1 Today Overview GL, GLU, GLUT, and GLUI First example OpenGL functions and
More informationComputer Graphics. OpenGL
Computer Graphics OpenGL What is OpenGL? OpenGL (Open Graphics Library) is a library for computer graphics It consists of several procedures and functions that allow a programmer to specify the objects
More information1 (Practice 1) Introduction to OpenGL
1 (Practice 1) Introduction to OpenGL This first practical is intended to get you used to OpenGL command. It is mostly a copy/paste work. Try to do it smartly by tweaking and messing around with parameters,
More informationAnnouncement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12
Announcement Homework 1 has been posted in dropbox and course website Due: 1:15 pm, Monday, September 12 Today s Agenda Primitives Programming with OpenGL OpenGL Primitives Polylines GL_POINTS GL_LINES
More informationBasic Graphics Programming
CSCI 480 Computer Graphics Lecture 2 Basic Graphics Programming January 11, 2012 Jernej Barbic University of Southern California http://www-bcf.usc.edu/~jbarbic/cs480-s12/ Graphics Pipeline OpenGL API
More information// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations
#include int main(int argc, char** argv) { glutinit(&argc, argv); Typical OpenGL/GLUT Main Program // GLUT, GLU, and OpenGL defs // program arguments // initialize glut and gl // double buffering
More informationby modifying the glutinitwindowsize() function you can change the screen size to whatever you please.
Zoe Veale Lab 2 Draw2 part 1: I edited the glutinitwindowsize() function tom change the size of my screen window. int main(int argc, char** argv) glutinit(&argc, argv); //initialize toolkit glutinitdisplaymode
More informationCS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008
CS559: Computer Graphics Lecture 12: OpenGL Li Zhang Spring 2008 Reading Redbook Ch 1 & 2 So far: 3D Geometry Pipeline Model Space (Object Space) Rotation Translation Resizing World Space M Rotation Translation
More informationTeacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using
Teacher Assistant : Tamir Grossinger email: tamirgr@gmail.com Reception hours: by email - Building 37 / office -102 Assignments: 4 programing using C++ 1 theoretical You can find everything you need in
More information11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)
CSCI 420 Computer Graphics Lecture 2 Basic Graphics Programming Teaching Assistant Yijing Li Office hours TBA Jernej Barbic University of Southern California Graphics Pipeline OpenGL API Primitives: Lines,
More informationProgrammable Graphics Hardware
Programmable Graphics Hardware Ian Buck Computer Systems Laboratory Stanford University Outline Why programmable graphics hardware Vertex Programs Fragment Programs CG Trends 2 Why programmable graphics
More informationDisplay Lists in OpenGL
Display Lists in OpenGL Display lists are a mechanism for improving performance of interactive OpenGL applications. A display list is a group of OpenGL commands that have been stored for later execution.
More informationComp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program
Comp 410/510 Computer Graphics Spring 2017 Programming with OpenGL Part 2: First Program Objectives Refine the first program Introduce a standard program structure - Initialization Program Structure Most
More informationCS Computer Graphics: OpenGL, Continued
CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.
More informationCS Computer Graphics: OpenGL, Continued
CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.
More informationIntroduction to OpenGL
Introduction to OpenGL Tutorial 1: Create a window and draw a 2D square Introduction: The aim of the first tutorial is to introduce you to the magic world of graphics based on the OpenGL and GLUT APIs.
More informationProgramming with OpenGL Part 1: Background
Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Development of the OpenGL API
More informationClass of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.
Utah School of Computing Spring 13 Class of Algorithms Lecture Set Visible Surface Determination CS56 Computer Graphics From Rich Riesenfeld Spring 13 Object (Model) Space Algorithms Work in the model
More informationRendering. Part 1 An introduction to OpenGL
Rendering Part 1 An introduction to OpenGL Olivier Gourmel VORTEX Team IRIT University of Toulouse gourmel@irit.fr Image synthesis The Graphics Processing Unit (GPU): A highly parallel architecture specialized
More informationExercise 1 Introduction to OpenGL
Exercise 1 Introduction to OpenGL What we are going to do OpenGL Glut Small Example using OpenGl and Glut Alexandra Junghans 2 What is OpenGL? OpenGL Two Parts most widely used and supported graphics API
More informationInformation Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)
11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere
More informationComputer graphics MN1
Computer graphics MN1 Hierarchical modeling Transformations in OpenGL glmatrixmode(gl_modelview); glloadidentity(); // identity matrix gltranslatef(4.0, 5.0, 6.0); glrotatef(45.0, 1.0, 2.0, 3.0); gltranslatef(-4.0,
More informationCS 4204 Computer Graphics
CS 4204 Computer Graphics OpenGL Basics Yong Cao Virginia Tech References: 2001 Siggraph, An Interactive Introduction to OpenGL Programming, Dave Shreiner,Ed Angel, Vicki Shreiner Official Presentation
More informationUsing OpenGL with CUDA
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
More informationToday s Agenda. Basic design of a graphics system. Introduction to OpenGL
Today s Agenda Basic design of a graphics system Introduction to OpenGL Image Compositing Compositing one image over another is most common choice can think of each image drawn on a transparent plastic
More informationIntroduction to OpenGL
CS100433 Introduction to OpenGL Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University Before OpenGL Let s think what is need
More informationgvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT
gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT Dr Franck P. Vidal 4 th September 2014 1 Contents Table of contents 2 List of figures 3 List of listings 3 1 Introduction 4
More informationAn Interactive Introduction to OpenGL Programming
An Interactive Introduction to OpenGL Programming Course # 29 Dave Shreiner Ed Angel Vicki Shreiner Table of Contents Introduction...iv Prerequisites...iv Topics...iv Presentation Course Notes...vi An
More informationGraphics Programming
Graphics Programming 3 rd Week, 2011 OpenGL API (1) API (application programming interface) Interface between an application program and a graphics system Application Program OpenGL API Graphics Library
More informationOpenGL Tutorial. Ceng 477 Introduction to Computer Graphics
OpenGL Tutorial Ceng 477 Introduction to Computer Graphics Adapted from: http://www.cs.princeton.edu/courses/archive/spr06/cos426/assn3/opengl_tutorial.ppt OpenGL IS an API OpenGL IS nothing more than
More informationC++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson
C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson Syllabus 1) First program and introduction to data types and control structures with applications for games learning how to use the programming
More informationCS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008
CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008 2008/2/3 Slide 2 I Am Your TA Name : Wei-Wen Wen Feng 4th Year Graduate Student in Graphics I will be Holding discussion/tutorial
More informationComputer Graphics Introduction to OpenGL
Computer Graphics 2015 3. Introduction to OpenGL Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2015-09-28 2. 2D Graphics Algorithms (cont.) Rasterization Computer Graphics @ ZJU Hongxin Zhang,
More informationLecture 2 CISC440/640 Spring Department of Computer and Information Science
Lecture 2 CISC440/640 Spring 2015 Department of Computer and Information Science Today s Topic The secrets of Glut-tony 2 So let s do some graphics! For the next week or so this is your world: -1 1-1 1
More informationIntroduction to Programmable GPUs CPSC 314. Real Time Graphics
Introduction to Programmable GPUs CPSC 314 Introduction to GPU Programming CS314 Gordon Wetzstein, 02/2011 Real Time Graphics Introduction to GPU Programming CS314 Gordon Wetzstein, 02/2011 1 GPUs vs CPUs
More informationCameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field
Cameras (and eye) Ideal Pinhole Real Pinhole Real + lens Depth of field 1 Z-buffer How do we draw objects? Polygon Based Fast Raytracing Ray/Object intersections Slow Copyright Pixar 2 Raytracing for each
More information(21) OpenGL GUI. OpenGL GUI 1 UNIX MAGAZINE UNIX. SGI (Silicon Graphics Inc.) Windows PC GUI. UNIX Windows GUI. Java. 1 prefposition() X X
(21) OpenGL GUI UNIX Windows Macintosh UNIX Windows PC SGI (Silicon Graphics Inc.) Windows PC GUI UNIX Windows GUI Java OpenGL OpenGL SGI 3 / GL GUI OpenGL GL OpenGL SGI 3 GL SGI 3 / 3 1 GL /* GL sample
More informationComputer Graphics, Chapt 08
Computer Graphics, Chapt 08 Creating an Image Components, parts of a scene to be displayed Trees, terrain Furniture, walls Store fronts and street scenes Atoms and molecules Stars and galaxies Describe
More information2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.
Erik Anchondo 1-29-19 cse 520 lab 3 1. Wrote a shader program to display three colored triangles, with one of each triangle being red, green, and blue. The colors change which triangle they are applied
More informationErik Anchondo cse 520 lab 4
Erik Anchondo 2-6-19 cse 520 lab 4 1. Wrote a glsl program that displays a colored tetrahedron. The tetrahedron starts to rotate on the x axis when the mouse button is clicked once. If the mouse button
More informationProgramming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Objectives Develop a more sophisticated
More informationAn Overview GLUT GLSL GLEW
OpenGL, GLUT, GLEW, GLSL An Overview GLUT GLEW GLSL Objectives Give you an overview of the software that you will be using this semester OpenGL, GLUT, GLEW, GLSL What are they? How do you use them? What
More informationCS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.
CS 380 Introduction to Computer Graphics LAB (1) : OpenGL Tutorial 2018. 03. 05 Reference : Foundations of 3D Computer Graphics, Steven J. Gortler Goals Understand OpenGL pipeline Practice basic OpenGL
More informationAssignment 1. Simple Graphics program using OpenGL
Assignment 1 Simple Graphics program using OpenGL In this assignment we will use basic OpenGL functions to draw some basic graphical figures. Example: Consider following program to draw a point on screen.
More informationLecture 3 Advanced Computer Graphics (CS & SE )
Lecture 3 Advanced Computer Graphics (CS & SE 233.420) Programming with OpenGL Program Structure Primitives Attributes and States Programming in three dimensions Inputs and Interaction Working with Callbacks
More informationCS Computer Graphics: Intro to OpenGL
CS 543 - Computer Graphics: Intro to OpenGL by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) OpenGL Basics Last time: What is Computer Graphics? What is a graphics library What to expect
More informationCS Computer Graphics: Intro to OpenGL
CS 543 - Computer Graphics: Intro to OpenGL by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) OpenGL Basics Last time: What is Computer Graphics? What is a graphics library What to expect
More information2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-
2.1 What is OpenGL? -23-2. OpenGL -I - Device-independent, application program interface (API) to graphics hardware - 3D-oriented - Event-driven Things OpenGL can do: - wireframe models - depth-cuing effect
More information2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3
CSCI 420 Computer Graphics Lecture 3 Interaction Jernej Barbic University of Southern California [Angel Ch. 2] Triangles (Clarification) Can be any shape or size Well-shaped triangles have advantages for
More informationComputer graphics MN1
Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? HowdoI useit? Rendering pipeline Points, vertices, lines, polygons Matrices and transformations Lighting and shading Code examples
More informationGraphics Hardware and OpenGL
Graphics Hardware and OpenGL Ubi Soft, Prince of Persia: The Sands of Time What does graphics hardware have to do fast? Camera Views Different views of an object in the world 1 Camera Views Lines from
More informationComputer Graphics Course 2005
Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups:
More informationInteraction. CSCI 420 Computer Graphics Lecture 3
CSCI 420 Computer Graphics Lecture 3 Interaction Jernej Barbic University of Southern California Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations [Angel Ch.
More informationComputer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)
Computer Graphics (CS 47) Lecture : Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations in OpenGL
More informationAPI for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3
OpenGL Introduction Introduction OpenGL OpenGL is an API for computer graphics. Hardware-independent Windowing or getting input is not included in the API Low-level Only knows about triangles (kind of,
More informationIntroduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012
Introduction to OpenGL CSCI 4229/5229 Computer Graphics Fall 2012 OpenGL by Example Learn OpenGL by reading nehe.gamedev.net Excellent free tutorial Code available for many platforms and languages OpenGL:
More informationAn Introduction to. Graphics Programming
An Introduction to Graphics Programming with Tutorial and Reference Manual Toby Howard School of Computer Science The University of Manchester V3.4 Contents 1 About this manual 1 1.1 How to read this manual................................
More informationInteraction Computer Graphics I Lecture 3
15-462 Computer Graphics I Lecture 3 Interaction Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations January 21, 2003 [Angel Ch. 3] Frank Pfenning Carnegie Mellon
More informationCg(3) Cg Core Runtime API Cg(3) C g Anmulti-platform, multi-api C-based programming language for GPUs
Cg(3) Cg Core Runtime API Cg(3) C g Anmulti-platform, multi-api C-based programming language for GPUs Cg is a high-level programming language designed to compile to the instruction sets of the programmable
More informationPhilip Calderon CSE 520 Lab 3 Color Shader
Philip Calderon CSE 520 Lab 3 Color Shader Summary: The purpose of lab 4 is to produce a pyramid tetrahedron that we are able to rotate it when clicked. Part 1: Color Tetrahedron Part 2: Rotation to show
More informationLecture 3. Understanding of OPenGL programming
Lecture 3 Understanding of OPenGL programming What is OpenGL GL: stands for Graphic Library Software interface for rendering purposes for 2D or 3D geometric data objects. Various Pieces gl: The basic libraries.
More informationIntro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin
Intro to OpenGL III Don Fussell Computer Science Department The University of Texas at Austin University of Texas at Austin CS354 - Computer Graphics Don Fussell Where are we? Continuing the OpenGL basic
More informationCOMPUTER GRAPHICS LAB # 3
COMPUTER GRAPHICS LAB # 3 Chapter 2: COMPUTER GRAPHICS by F.S HILLs. Initial steps in drawing figures (polygon, rectangle etc) Objective: Basic understanding of simple code in OpenGL and initial steps
More informationBasics of GPU-Based Programming
Module 1: Introduction to GPU-Based Methods Basics of GPU-Based Programming Overview Rendering pipeline on current GPUs Low-level languages Vertex programming Fragment programming High-level shading languages
More informationProgramming with OpenGL Part 1: Background
Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Development of the OpenGL API
More informationIntroduction to OpenGL: Part 2
Introduction to OpenGL: Part 2 Introduction to OpenGL: Part 2 A more complex example recursive refinement Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous
More informationIntroduction to OpenGL
Introduction to OpenGL Banafsheh Azari http://www.uni-weimar.de/cms/medien/cg.html What You ll See Today What is OpenGL? Related Libraries OpenGL Command Syntax B. Azari http://www.uni-weimar.de/cms/medien/cg.html
More informationCOMP 371/4 Computer Graphics Week 1
COMP 371/4 Computer Graphics Week 1 Course Overview Introduction to Computer Graphics: Definition, History, Graphics Pipeline, and Starting Your First OpenGL Program Ack: Slides from Prof. Fevens, Concordia
More information1.2 Basic Graphics Programming
Fall 2018 CSCI 420: Computer Graphics 1.2 Basic Graphics Programming Hao Li http://cs420.hao-li.com 1 Last time Last Time Story Computer Graphics Image Last Time 3D Printing 3D Capture Animation Modeling
More informationInteraction. CSCI 480 Computer Graphics Lecture 3
CSCI 480 Computer Graphics Lecture 3 Interaction January 18, 2012 Jernej Barbic University of Southern California Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations
More informationComputer Graphics Primitive Attributes
Computer Graphics 2015 4. Primitive Attributes Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2015-10-12 Previous lessons - Rasterization - line - circle /ellipse? => homework - OpenGL and
More informationAn Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner
An Interactive Introduction to OpenGL and OpenGL ES Programming Ed Angel Dave Shreiner Welcome This morning s Goals and Agenda Describe the OpenGL APIs and their uses Demonstrate and describe OpenGL s
More informationProgramming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 Objectives Simple Shaders - Vertex shader - Fragment shaders Programming shaders with
More information