This Lecture. Introduction to OpenGL. Outline. Why OpenGL? Programmer s View. Foundations of Computer Graphics

Similar documents
To Do. Demo: Surreal (now 15+ years ago) This Lecture. Outline. Computer Graphics. CSE 167 [Win 19], Lecture 6: OpenGL 1 Ravi Ramamoorthi

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012)

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

Methodology for Lecture

To Do. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012)

Basic Graphics Programming

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

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

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

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Introduction to Computer Graphics with OpenGL/GLUT

Precept 2 Aleksey Boyko February 18, 2011


Basic Graphics Programming

Computer Graphics. OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

OpenGL refresher. Advanced Computer Graphics 2012

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

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

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

An Overview GLUT GLSL GLEW

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

CS 4204 Computer Graphics

Interaction. CSCI 420 Computer Graphics Lecture 3

VR-programming tools (procedural) More VRML later in this course! (declarative)

Exercise 1 Introduction to OpenGL

Computer Graphics. Bing-Yu Chen National Taiwan University

RECITATION - 1. Ceng477 Fall

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 432 Interactive Computer Graphics

Computer graphics MN1

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

CS 432 Interactive Computer Graphics

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS 548: COMPUTER GRAPHICS INTRODUCTION TO OPENGL AND GLUT SPRING 2015 DR. MICHAEL J. REALE

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

Programming using OpenGL: A first Introduction

Erik Anchondo cse 520 lab 4

Rendering. Part 1 An introduction to OpenGL

Lectures OpenGL Introduction

Display Lists in OpenGL

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

Computer Graphics 1 Computer Graphics 1

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Philip Calderon CSE 520 Lab 3 Color Shader

CS 432 Interactive Computer Graphics

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

CSE 167. Discussion 03 ft. Glynn 10/16/2017

Interaction Computer Graphics I Lecture 3

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

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

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

LECTURE 02 OPENGL API

Introduction to OpenGL

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

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

Drawing Primitives. OpenGL basics

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

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

COMPUTER GRAPHICS LAB # 3

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

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

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

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

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Computer Graphics Course 2005

Geometry Shaders. And how to use them

Announcements OpenGL. Computer Graphics. Spring CS4815

Introduction to OpenGL: Part 2

Lecture 3 Advanced Computer Graphics (CS & SE )

Graphics Programming

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

Interaction. CSCI 480 Computer Graphics Lecture 3

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Lecture 3. Understanding of OPenGL programming

Computer Graphics Introduction to OpenGL

Computer Graphics, Chapt 08

Computer Graphics (Basic OpenGL)

1.2 Basic Graphics Programming

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Graphics Pipeline & APIs

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Transcription:

Foundations of Computer Graphics Overview and Motivation This Lecture Introduction to OpenGL and simple demo code mytest1.cpp ; you compiled mytest3.cpp for HW 0 I am going to show (and write) actual code Code helps you understand HW 2 better Simple demo of mytest1 This lecture deals with very basic OpenGL setup. Next 2 lectures will likely be more interesting Initializing s Introduction to OpenGL OpenGL is a graphics API Portable software library (platform-independent) Layer between programmer and graphics hardware Uniform instruction set (hides different capabilities) OpenGL can fit in many places Between application and graphics system Between higher level API and graphics system Why OpenGL? Why do we need OpenGL or an API? Encapsulates many basic functions of 2D/3D graphics Think of it as high-level language (C++) for graphics History: Introduced SGI in 92, maintained by Khronos Precursor for DirectX, WebGL, Java3D etc. Programmer s View Application Application Graphics Package OpenGL Application Programming Interface Hardware and software (graphics card) Output Device Input Device Input Device Slide inspired by Greg Humphreys 1

Vertices Images OpenGL Rendering Pipeline Programmable in Modern GPUs (Vertex ) Geometry Primitive Operations Pixel Operations Scan Conversion (Rasterize) Texture Memory Programmable in Modern GPUs (Fragment ) Fragment Operations Framebuffer GPUs and Programmability Since 2003, can write vertex/pixel shaders Fixed function pipeline special type of shader Like writing C programs (see GLSL book) Performance >> CPU (even used for non-graphics) Operate in parallel on all vertices or fragments Traditional Approach: Fixed function pipeline (state machine) New Development (2003-): Programmable pipeline Initializing s Foundations of Computer Graphics Basic Setup and Buffers, Matrix Modes Initializing s Buffers and Window Interactions Buffers: Color (front, back, left, right), depth (z), accumulation, stencil. When you draw, you write to some buffer (most simply, front and depth) Buffers also used for vertices etc. Buffer data and buffer arrays (will see in creating objects) No window system interactions (for portability) But can use GLUT (or Motif, GLX, Tcl/Tk) Callbacks to implement mouse, keyboard interaction 2

Basic setup (can copy; slight OS diffs) int main(int argc, char** argv) glutinit(&argc, argv); // Requests the type of buffers (Single, RGB). // Think about what buffers you would need... glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); // Need to add GLUT_3_2_CORE_PROFILE for Apple/Mac OS glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow ("Simple Demo with s"); // glewinit(); // GLEW related stuff for non-apple systems init (); // Always initialize first // Now, we define callbacks and functions for various tasks.... Basic setup (can copy; slight OS diffs) int main(int argc, char** argv)... // Now, we define callbacks and functions for various tasks. glutdisplayfunc(display); glutreshapefunc(reshape) ; glutkeyboardfunc(keyboard); glutmousefunc(mouse) ; glutmotionfunc(mousedrag) ; glutmainloop(); // Start the main code deletebuffers(); //Termination. Delete buffers generated in init() return 0; /* ANSI C requires main to return int. */ Initializing s Viewing in OpenGL Inspired by old OpenGL. Now, only best practice, not requirement You could do your own thing, but this is still the best way to develop viewing Viewing consists of two parts Object positioning: model view transformation matrix View projection: projection transformation matrix Old OpenGL (no longer supported/taught in 167x), two matrix stacks GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX Can push and pop matrices onto stacks New OpenGL: Use C++ STL templates to make stacks as needed e.g. stack <mat4> modelview ; modelview.push(mat4(1.0)) ; GLM libraries replace many deprecated commands. Include mat4 Viewing in OpenGL Convention: camera always at the origin, pointing in the z direction Transformations move objects relative to the camera In old OpenGL, Matrices are column-major and right-multiply top of stack. (Last transform in code is first actually applied). In new GLM, similarly (read the assignment notes and documentation). Basic initialization code for viewing #include <GL/glut.h> //also <GL/glew.h>; <GLUT/glut.h> for Mac OS #include <stdlib.h> //also stdio.h, assert.h, glm, others int mouseoldx, mouseoldy ; // For mouse motion GLfloat eyeloc = 2.0 ; // Where to look from; initially 0-2, 2 glm::mat4 projection, modelview; // The mvp matrices themselves void init (void) /* select clearing color */ glclearcolor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ projection = glm::mat4(1.0f); // The identity matrix // Think about this. Why is the up vector not normalized? modelview = glm::loakat(glm::vec3(0,-eyeloc,eyeloc), glm::vec3(0,0,0), glm::vec3(0,1,1)) ; // (To be cont d). Geometry and shader set up later... 3

Foundations of Computer Graphics Window System Interaction and Callbacks Initializing s Window System Interaction Not part of OpenGL Toolkits (GLUT) available (also freeglut) Callback functions for events (similar to X, Java,) Keyboard, Mouse, etc. Open, initialize, resize window Our main func included glutdisplayfunc(display); glutreshapefunc(reshape) ; glutkeyboardfunc(keyboard); glutmousefunc(mouse) ; glutmotionfunc(mousedrag) ; Basic window interaction code /* Defines what to do when various keys are pressed */ void keyboard (unsigned char key, int x, int y) switch (key) case 27: // Escape to quit exit(0) ; break ; default: break ; Basic window interaction code /* Reshapes the window appropriately */ void reshape(int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); // Note that the field of view takes in a radian angle projection = glm::perspective(30.0f / 180.0f * glm::pi<float>(), (GLfloat)w / (GLfloat)h, 1.0f, 10.0f); gluniformmatrix4fv(projectionpos,1, GL_FALSE, &projection[0][0]); // To send the projection matrix to the shader Mouse motion (demo) void mouse(int button, int state, int x, int y) if (button == GLUT_LEFT_BUTTON) if (state == GLUT_UP) // Do Nothing ; else if (state == GLUT_DOWN) mouseoldx = x ; mouseoldy = y ; // so we can move wrt x, y else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) // Reset glulookat eyeloc = 2.0 ; modelview = glm::lookat(glm::vec3(0, -eyeloc, eyeloc), glm::vec3(0, 0, 0), glm::vec3(0, 1, 1)); // Send the updated matrix to the shader gluniformmatrix4fv(modelviewpos,1,gl_false,&modelview[0][0]); glutpostredisplay() ; // Redraw scene 4

Mouse drag (demo) void mousedrag(int x, int y) int yloc = y - mouseoldy ; // We will use the y coord to zoom in/out eyeloc += 0.005*yloc ; // Where do we look from if (eyeloc < 0) eyeloc = 0.0 ; mouseoldy = y ; /* Set the eye location */ modelview = glm::lookat(glm::vec3(0, -eyeloc, eyeloc), glm::vec3(0, 0, 0), glm::vec3(0, 1, 1)); // Send the updated matrix over to the shader gluniformmatrix4fv(modelviewpos,1,gl_false,&modelview[0][0]); Foundations of Computer Graphics Drawing Basic OpenGL Primitives glutpostredisplay() ; Initializing s New OpenGL Primitives (fewer) Points Lines (also strips, loops) Polygon Triangle Quad Quad Strip Triangle Strip Triangle Fan Geometry Points (GL_POINTS) Stored in Homogeneous coordinates Line segments (GL_LINES) Also (GL_LINE_STRIP, GL_LINE_LOOP) Triangles (GL_TRIANGLES) Also strips, fans (GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN) More complex primitives (GLUT): Sphere, teapot, cube, Must now be converted into triangles (which is what skeleton does) Old OpenGL: Drawing Enclose vertices between glbegin() glend() pair Can include normal C code and attributes like the colors Inside are commands like glvertex3f, glcolor3f Attributes must be set before the vertex Assembly line (pass vertices, transform, shade) These are vertex, fragment shaders on current GPUs Immediate Mode: Sent to server and drawn 5

Old OpenGL: Drawing (not used) void display(void) glclear (GL_COLOR_BUFFER_BIT); // draw polygon (square) of unit length centered at the origin // This code draws each vertex in a different color. glbegin(gl_polygon); glcolor3f (1.0, 0.0, 0.0); glvertex3f (0.5, 0.5, 0.0); glcolor3f (0.0, 1.0, 0.0); glvertex3f (-0.5, 0.5, 0.0); glcolor3f (0.0, 0.0, 1.0); glvertex3f (-0.5, -0.5, 0.0); glcolor3f (1.0, 1.0, 1.0); glvertex3f (0.5, -0.5, 0.0); glend(); glflush () ; (-.5,.5) GREEN (-.5, -.5) BLUE (.5,.5) RED (.5, -.5) WHITE Old OpenGL: Drawing Client-Server model (client generates vertices, server draws) even if on same machine glflush() forces client to send network packet glfinish() waits for ack, sparingly use synchronization New OpenGL: Vertex Array Objects (next) Modern OpenGL: Floor Specification const GLfloat floorverts[4][3] = 0.5, 0.5, 0.0,-0.5, 0.5, 0.0,-0.5, -0.5, 0.0, 0.5, -0.5, 0.0 ; const GLfloat floorcol[4][3] = 1.0, 0.0, 0.0,0.0, 1.0, 0.0,0.0, 0.0, 1.0,1.0, 1.0, 1.0 ; const GLubyte floorinds[1][6] = 0, 1, 2, 0, 2, 3 ; //triangles const GLfloat floorverts2[4][3] = 0.5, 0.5, 1.0,-0.5, 0.5, 1.0,-0.5, -0.5, 1.0,0.5, -0.5, 1.0 ; const GLfloat floorcol2[4][3] = 1.0, 0.0, 0.0,1.0, 0.0, 0.0,1.0, 0.0, 0.0,1.0, 0.0, 0.0 ; const GLubyte floorinds2[1][6] = 0, 1, 2, 0, 2, 3 ; //triangles Modern OpenGL: Vertex Array Objects const int numobjects = 2 ; // number of objects for buffer const int numperobj = 3 ; // Vertices, colors, indices GLuint VAOs[numobjects]; // A Vertex Array Object per object GLuint buffers[numperobj*numobjects]; // List of buffers geometric data GLuint objects[numobjects]; // For each object GLenum PrimType[numobjects];// Primitive Type (triangles, strips) GLsizei NumElems[numobjects] ; // Number of geometric elements // Floor Geometry is specified with a vertex array enum Vertices, Colors, Elements ; // For arrays for object enum FLOOR, FLOOR2 ; // For objects, for the floor //------In init below (creates buffer objects for later use)------ Modern OpenGL: Vertex Array Objects const int numobjects = 2 ; // number of objects for buffer const int numperobj = 3 ; // Vertices, colors, indices GLuint VAOs[numobjects]; // A Vertex Array Object per object GLuint buffers[numperobj*numobjects] ; // List of buffers geometric data //... //------In init below (creates buffer objects for later use)------ glgenvertexarrays(numobjects, VAOs); //create unique identifiers glgenbuffers(numperobj*numobjects, buffers); //and for buffers void deletebuffers() // Like a destructor gldeletevertexarrays(numobjects, VAOs); gldeletebuffers(numperobj*numobjects, buffers); Modern OpenGL: Initialize Buffers void initobject (GLuint object, GLfloat * vert, GLint sizevert, GLfloat * col, GLint sizecol, GLubyte * inds, GLint sizeind, GLenum type) int offset = object * numperobj; glbindvertexarray(vaos[object]); glbindbuffer(gl_array_buffer, buffers[vertices+offset]) ; glbufferdata(gl_array_buffer, sizevert, vert,gl_static_draw); // Use layout location 0 for the vertices glenablevertexattribarray(0); glvertexattribpointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(glfloat), 0); glbindbuffer(gl_array_buffer, buffers[colors+offset]) ; glbufferdata(gl_array_buffer, sizecol, col,gl_static_draw); // Use layout location 1 for the colors //... 6

Modern OpenGL: Initialize Buffers void initobject (GLuint object, GLfloat * vert, GLint sizevert, GLfloat * col, GLint sizecol, GLubyte * inds, GLint sizeind, GLenum type) //... // Use layout location 1 for the colors glenablevertexattribarray(1); glvertexattribpointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(glfloat), 0); glbindbuffer(gl_element_array_buffer, buffers[elements+offset]) ; glbufferdata(gl_element_array_buffer, sizeind, inds,gl_static_draw); PrimType[object] = type; NumElems[object] = sizeind; // Prevent further modification of this VAO by unbinding it glbindvertexarray(0); Modern OpenGL: Draw Vertex Object void drawobject(gluint object) glbindvertexarray(vaos[object]); gldrawelements(primtype[object], NumElems[object], GL_UNSIGNED_BYTE, 0); glbindvertexarray(0); //unbind void display(void) glclear (GL_COLOR_BUFFER_BIT); // clear all pixels drawobject(floor) ; drawobject(floor2) ; glflush (); // start processing buffered OpenGL commands Initialization for Drawing, Shading #include "shaders.h" GLuint vertexshader, fragmentshader, shaderprogram ; // shaders // Initialization in init() for Drawing glgenvertexarrays(numobjects, VAOs) ; glgenbuffers(numperobj*numobjects, buffers) ; initobject(floor, (GLfloat *) floorverts, sizeof(floorverts), (GLfloat *) floorcol, sizeof (floorcol), (GLubyte *) floorinds, sizeof (floorinds), GL_TRIANGLES) ; initobject(floor2, (GLfloat *) floorverts2, sizeof(floorverts2), (GLfloat *) floorcol2, sizeof (floorcol2), (GLubyte *) floorinds2, sizeof (floorinds2), GL_TRIANGLES) ; // In init() for s, discussed next vertexshader = initshaders(gl_vertex_shader, "shaders/nop.vert") ; fragmentshader = initshaders(gl_fragment_shader, "shaders/nop.frag") ; shaderprogram = initprogram(vertexshader, fragmentshader) ; Demo (change colors) Foundations of Computer Graphics Initializing s Initializing s 7

Full OpenGL Pipeline Vertex Tessellation Control Tessellation Evaluation Geometry Full OpenGL Pipeline Vertex Tessellation Control Tessellation Evaluation Geometry Primitive Setup Clipping Rasterization Primitive Setup Clipping Rasterization Texture/Image Data (Program) Fragment Final Pixel Color (Image) User/program generates original vertices, textures We cover programmable vertex and fragment shaders in course OpenGL primitive setup, clipping, rasterization not programmable Texture/Image Data (Program) Fragment Final Pixel Color (Image) Tessellation shaders take patches (splines) to output vertices Geometry shaders process primitives, can add/remove geometry Not covered in this course Simplified OpenGL Pipeline User specifies vertices (via vertex arrays) For each vertex in parallel OpenGL calls user-specified vertex shader: Transform vertex (ModelView, Projection), other ops For each primitive, OpenGL rasterizes Generates a fragment for each pixel the primitive covers For each fragment in parallel OpenGL calls user-specified fragment shader: Shading and lighting calculations OpenGL handles z-buffer depth test unless overwritten Setup Initializing (shader itself discussed later) 1. Create shader (Vertex and Fragment) 2. Compile shader 3. Attach shader to program 4. Link program 5. Use program Setup source is just sequence of strings Similar steps to compile a normal program Initialization Code GLuint initshaders (GLenum type, const char *filename) // Using GLSL shaders, OpenGL book, page 679 of 7 th edition GLuint shader = glcreate(type) ; GLint compiled ; string str = textfileread (filename) ; const GLchar * cstr = str.c_str() ; glsource (shader, 1, &cstr, NULL) ; glcompile (shader) ; glgetiv (shader, GL_COMPILE_STATUS, &compiled) ; if (!compiled) shadererrors (shader) ; throw 3 ; return shader ; 8

Linking Program GLuint initprogram (GLuint vertexshader, GLuint fragmentshader) GLuint program = glcreateprogram() ; GLint linked ; glattach(program, vertexshader) ; glattach(program, fragmentshader) ; gllinkprogram(program) ; glgetprogramiv(program, GL_LINK_STATUS, &linked) ; if (linked) gluseprogram(program) ; else programerrors(program) ; throw 4 ; cout<<" program successfully attached and linked." << endl; return program ; Basic (nop) vertex shader In shaders/ nop.vert.glsl nop.frag.glsl Written in GLSL (GL Shading Language) Vertex (out values interpolated to fragment) # version 330 core // Do not modify the above version directive to anything older. // inputs layout (location = 0) in vec3 position; layout (location = 1) in vec3 color; // outputs, if any out vec3 Color; // Uniform variables uniform mat4 modelview; uniform mat4 projection; void main() //... Basic (nop) vertex shader In shaders/ nop.vert.glsl nop.frag.glsl Written in GLSL (GL Shading Language) Vertex (out values interpolated to fragment) # version 330 core layout (location = 0) in vec3 position; layout (location = 1) in vec3 color; // outputs, if any out vec3 Color; // Uniform variables uniform mat4 modelview; uniform mat4 projection; void main() gl_position = projection * modelview * vec4(position, 1.0f); Color = color; // Just forward this color to the fragment shader Basic (nop) fragment shader # version 330 core // Do not modify the version directive to anything older than 330. // Fragment shader inputs are outputs of same name from vertex shader in vec3 Color; // Uniform variables (none) // Output out vec4 fragcolor; void main (void) fragcolor = vec4(color, 1.0f); 9