Question

Next, we create two helper classes to allocate and structure memory to hold the data to be used by the shaders. The shader code we will write will replace all the OpenGL drawing code we've written to date. In some ways, the shader code will also simplify the OpenGL drawing code, but to work, the shaders still need to know about vertices, colors, projection and view matrices, and other data. The first class we create will be in a script called GraphicsData. py. Create this file and add the following code to it: from OpenGL.GL import * import numpy as np class GraphicsData(): def_init_(self, data_type, data): self.data_type = data_type self.data $=$ data self.buffer_ref = glGenBuffers(1) self.load() def load(self) : data $=\mathrm{np} \cdot \operatorname{array}($ self.data, np.float32) glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref) glBufferData (GL_ARRAY_BUFFER, data.ravel (), GL_STATIC_DRAW) def create_variable(self, program_id, variable_name) : variable_id = glGetAttribLocation(program_id, variable_name) glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref) if self.data_type $==$ "vec3": glVertexAttribPointer(variable_id, 3, GL_FLOAT, False, 0, None) elif self.data_type == "vec2" : glVertexAttribPointer(variable_id, 2, GL_FLOAT, False, 0, None) glEnableVertexAttribArray (variable_id)

   Next, we create two helper classes to allocate and structure memory to hold the data to be used by the shaders. The shader code we will write will replace all the OpenGL drawing code we've written to date. In some ways, the shader code will also simplify the OpenGL drawing code, but to work, the shaders still need to know about vertices, colors, projection and view matrices, and other data. The first class we create will be in a script called GraphicsData. py. Create this file and add the following code to it:
from OpenGL.GL import *
import numpy as np
class GraphicsData():
def_init_(self, data_type, data):
self.data_type = data_type
self.data $=$ data
self.buffer_ref = glGenBuffers(1)
self.load()
def load(self) :
data $=\mathrm{np} \cdot \operatorname{array}($ self.data, np.float32)
glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref)
glBufferData (GL_ARRAY_BUFFER, data.ravel (),
GL_STATIC_DRAW)
def create_variable(self, program_id,
variable_name) :
variable_id = glGetAttribLocation(program_id,
variable_name)
glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref)
if self.data_type $==$ "vec3":
glVertexAttribPointer(variable_id, 3,
GL_FLOAT,
False, 0, None)
elif self.data_type == "vec2" :
glVertexAttribPointer(variable_id, 2,
GL_FLOAT,
False, 0, None)
glEnableVertexAttribArray (variable_id)
Show more…
Mathematics for Game Programming and Computer Graphics: Explore the essential mathematics for creating, rendering, and manipulating 3D virtual environments
Mathematics for Game Programming and Computer Graphics: Explore the essential mathematics for creating, rendering, and manipulating 3D virtual environments
Penny de Byl 1st Edition
Chapter 17, Problem 5 ↓

Instant Answer

verified

Step 1

py and add the following code to it: ```python from OpenGL.GL import * import numpy as np class GraphicsData(): def __init__(self, data_type, data): self.data_type = data_type self.data = data self.buffer_ref = glGenBuffers(1)   Show more…

Show all steps

lock
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Next, we create two helper classes to allocate and structure memory to hold the data to be used by the shaders. The shader code we will write will replace all the OpenGL drawing code we've written to date. In some ways, the shader code will also simplify the OpenGL drawing code, but to work, the shaders still need to know about vertices, colors, projection and view matrices, and other data. The first class we create will be in a script called GraphicsData. py. Create this file and add the following code to it: from OpenGL.GL import * import numpy as np class GraphicsData(): def_init_(self, data_type, data): self.data_type = data_type self.data $=$ data self.buffer_ref = glGenBuffers(1) self.load() def load(self) : data $=\mathrm{np} \cdot \operatorname{array}($ self.data, np.float32) glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref) glBufferData (GL_ARRAY_BUFFER, data.ravel (), GL_STATIC_DRAW) def create_variable(self, program_id, variable_name) : variable_id = glGetAttribLocation(program_id, variable_name) glBindBuffer(GL_ARRAY_BUFFER, self.buffer_ref) if self.data_type $==$ "vec3": glVertexAttribPointer(variable_id, 3, GL_FLOAT, False, 0, None) elif self.data_type == "vec2" : glVertexAttribPointer(variable_id, 2, GL_FLOAT, False, 0, None) glEnableVertexAttribArray (variable_id)
Close icon
Play audio
Feedback
Powered by NumerAI
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever