Top Banner
Lecture 4 2/11/2019 Textures Professor provided an example showing how to transpose two images using OpenGL: Showed how to use arrow keys to interactively transition from one image to another. The geometry used is the two triangles from the previous lecture with the textures superimposed. Using external opensource library SOIL (Simple OpenGL Image Library) o #include <SOIL.h> o Can be found using: apt-get SOIL (integrated with ubuntu repository package manager) Declare global variable GL_float mix_value = 0.2f o Very important Rest of the setup for shaders is boilerplate from previous examples New stuff related to textures o Generate two texture maps to bind to geometry o texture1 and texture2 o set texture parameters, wrapping texture around edges of geometry o set texture filtering o load, create, and generate mipmaps convert image into texture map mipmap hierarchical representation of an image at various resolutions (for zooming in and out) for faster rendering at runtime o SOIL_load_image o glTexImage2d o glGenerateMipmap o SOIL_free_image_data o glBindTexture use vertices[] to map the image onto the geometry o affects how the images are laid out
7

Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Oct 04, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

TexturesProfessor provided an example showing how to transpose two images using OpenGL:

Showed how to use arrow keys to interactively transition from one image to another.

The geometry used is the two triangles from the previous lecture with the textures superimposed.

Using external opensource library SOIL (Simple OpenGL Image Library)o #include <SOIL.h>o Can be found using: apt-get SOIL (integrated with ubuntu

repository package manager) Declare global variable GL_float mix_value = 0.2f

o Very important Rest of the setup for shaders is boilerplate from previous examples New stuff related to textures

o Generate two texture maps to bind to geometryo texture1 and texture2o set texture parameters, wrapping texture around edges of

geometryo set texture filteringo load, create, and generate mipmaps

convert image into texture map mipmap hierarchical representation of an image at various

resolutions (for zooming in and out) for faster rendering at runtime

o SOIL_load_imageo glTexImage2do glGenerateMipmapo SOIL_free_image_datao glBindTexture

use vertices[] to map the image onto the geometry o affects how the images are laid outo two floating point values associated with each vertex and then a

texture coordinate when adding attribute to vertex, need to be mindful of the spacing/offset

of the data (in this example 8 floating-point values between vertex values)

inside display group we have three new things that we should take note of:

o first call shader programo then bind the texture

Page 2: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

active texture -> bind texture mapping to first texture and second texture

o pass mix_value to the shader, argument passed to shader to change its behavior on how it’s going to display the data

the draw the triangles and nothing new is happening after Looking at the shader.vs

o Data is laid out with input, position, and color coordinateo In the texture coordinate we take the x coordinate and 1-y

coordinate Looking at the shader.frag

o Input of the shader.frag is the output of the shader.vs key_callback() in main.cpp

o Enables use of keyboard to interact with the window at runtime

ArduinoOnto some hardware examples:

LED:

Resistor: 1 kOhm resistor in our kit

Current

Page 3: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

Transistor: b – base c – connector e – emitter allows Arduino to handle higher voltages, controls the flow of current

Capacitor:

Reduces/ slows down the fluctuations in current Holds a charge effectively Will use to implement a switch We should use the smaller capacitor in kit

Switch: Use to control current on/off Put the switch on the breadboard straddling the divider

Current

Page 4: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

oo May have to stretch the four pins

In class example LED switch circuit:

Page 5: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

The blue wire is 5v source Yellow wire is ground

Sketch code:

#define LED 12#define BUTTON 7

void setup() {pinMode(LED, OUTPUT);pinMode(BUTTON, INPUT);

Page 6: Textures - GitHub Pages · Web viewSOIL_free_image_data glBindTexture use vertices[] to map the image onto the geometry affects how the images are laid out two floating point values

Lecture 42/11/2019

}

void loop() {if (digitalRead(BUTTON) == HIGH) {

digitalWrite(LED, HIGH);delay(500);digitalWrite(LED, LOW);

}}