Guest User

Untitled

a guest
Jan 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. void OperateWithMainMatrix(ESContext* esContext, GLfloat offsetX, GLfloat offsetY, GLfloat offsetZ) {
  2.  
  3. UserData *userData = (UserData*) esContext->userData;
  4. ESMatrix modelview;
  5. ESMatrix perspective;
  6. //Manipulation with matrix
  7. ...
  8. glVertexAttribPointer(userData->positionLoc, 3, GL_FLOAT, GL_FALSE, 0, cubeFaces);
  9. //in cubeFaces coordinates verticles cube
  10. glVertexAttribPointer(userData->normalLoc, 3, GL_FLOAT, GL_FALSE, 0, cubeFaces);
  11. //for normals (use in fragment shaider for textures)
  12.  
  13. glEnableVertexAttribArray(userData->positionLoc);
  14. glEnableVertexAttribArray(userData->normalLoc);
  15.  
  16. // Load the MVP matrix
  17. glUniformMatrix4fv(userData->mvpLoc, 1, GL_FALSE,
  18. (GLfloat*)&userData->mvpMatrix.m[0][0]);
  19.  
  20. //Bind base map
  21. glActiveTexture(GL_TEXTURE0);
  22. glBindTexture(GL_TEXTURE_CUBE_MAP, userData->baseMapTexId);
  23.  
  24. //Set the base map sampler to texture unit to 0
  25. glUniform1i(userData->baseMapLoc, 0);
  26.  
  27. // Draw the cube
  28. glDrawArrays(GL_TRIANGLES, 0, 36);
  29. }
  30.  
  31. void Draw(ESContext *esContext)
  32. {
  33. UserData *userData = esContext->userData;
  34. // Set the viewport
  35. glViewport(0, 0, esContext->width, esContext->height);
  36.  
  37. // Clear the color buffer
  38. glClear(GL_COLOR_BUFFER_BIT);
  39.  
  40. // Use the program object
  41. glUseProgram(userData->programObject);
  42.  
  43. OperateWithMainMatrix(esContext, 0.0f, 0.0f, 0.0f);
  44.  
  45. eglSwapBuffers(esContext->eglDisplay, esContext->eglSurface);
  46. }
  47.  
  48. void Draw(ESContext *esContext)
  49. { ...
  50.  
  51. // Use the program object
  52. glUseProgram(userData->programObject);
  53.  
  54. OperateWithMainMatrix(esContext, 2.0f, 0.0f, 0.0f);
  55. OperateWithMainMatrix(esContext, 1.0f, 0.0f, 0.0f);
  56. OperateWithMainMatrix(esContext, 0.0f, 0.0f, 0.0f);
  57. OperateWithMainMatrix(esContext, -1.0f, 0.0f, 0.0f);
  58. OperateWithMainMatrix(esContext, -2.0f, 0.0f, 0.0f);
  59. eglSwapBuffers(esContext->eglDisplay, esContext->eglSurface);
  60. }
Add Comment
Please, Sign In to add comment