Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //##### Dice.mm
- - (void) setup{
- glGenVertexArraysOES(1, &_vertexArray);
- glBindVertexArrayOES(_vertexArray);
- glGenBuffers(1, &_indexBuffer);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*sizeof(GLushort), indices, GL_STATIC_DRAW);
- glGenBuffers(1, &_vertexBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
- glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
- glEnableVertexAttribArray(effect->vertCoord);
- glVertexAttribPointer(effect->vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(effect->toon_vertCoord);//dont even know if you can do this twice for a bound buffer, but how else would you send vert coords to a diff shader
- glVertexAttribPointer(effect->toon_vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glGenBuffers(1, &_normalBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, _normalBuffer);
- glBufferData(GL_ARRAY_BUFFER, numNormals*sizeof(GLfloat), normals, GL_STATIC_DRAW);
- glEnableVertexAttribArray(effect->normal);
- glVertexAttribPointer(effect->normal, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glGenBuffers(1, &_textureBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, _textureBuffer);
- glBufferData(GL_ARRAY_BUFFER, numTex*sizeof(GLfloat), tex, GL_STATIC_DRAW);
- glEnableVertexAttribArray(effect->texCoord);
- glVertexAttribPointer(effect->texCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
- glBindVertexArrayOES(0);
- }
- - (void) drawOutlines {
- if(selected){
- [EAGLContext setCurrentContext:context];
- glBindVertexArrayOES(_vertexArray);
- effect->modelViewMatrix = mvm;
- [effect drawOutline];
- glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
- }
- }
- - (void) draw {
- [EAGLContext setCurrentContext:context];
- glBindVertexArrayOES(_vertexArray);
- effect->modelViewMatrix = mvm;
- effect->numberColour = GLKVector4Make(numbers[colorSelected].r, numbers[colorSelected].g, numbers[colorSelected].b, 1);
- effect->faceColour = GLKVector4Make(faceColors[colorSelected].r, faceColors[colorSelected].g, faceColors[colorSelected].b, 1);
- [effect prepareToDraw];
- glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
- }
- //##### outside of the dice class, this is how I call the draw functions in the draw loop
- - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
- [EAGLContext setCurrentContext:self.RollView.context];
- [self update];
- glClearColor(0.9, 0.9, 0.9, 1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- for(int i = 0; i < self.profile.tableOfDice.count; i++){
- [[self.profile getDiceAt:i] drawOutlines];
- }
- for(int i = 0; i < self.profile.tableOfDice.count; i++){
- [[self.profile getDiceAt:i] draw];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement