fork download
  1. //////////////////////////////
  2. //Main Libary
  3. /////////////////////////////
  4. #define NO_SDL_GLEXT
  5. #include <glew.h>
  6. #include "SDL/SDL.H"
  7. #include "SDL/SDL_IMAGE.H"
  8. #include "SDL/SDL_OPENGL.H"
  9. #undef main
  10. #include <iostream>
  11. #include <cassert>
  12. #include <string>
  13. #include <algorithm>
  14. #include <boost/iostreams/stream.hpp>
  15. #include <libs/iostreams/example/container_device.hpp>
  16. #include <boost/filesystem.hpp>
  17. #include <boost/iostreams/categories.hpp>
  18. #include <boost/algorithm/string.hpp>
  19. #include <vector>
  20. #include <fstream>
  21. #include "GL/glu.h"
  22. #include <glm/glm.hpp>
  23. #include <glm/gtc/type_ptr.hpp>
  24. #include <glm/gtc/matrix_transform.hpp>
  25. /////////////////////////////
  26. using namespace std;
  27. using namespace boost::filesystem;
  28. namespace io = boost::iostreams;
  29. namespace ex = boost::iostreams::example;
  30. ////////////////////////////
  31.  
  32. //for holding the string
  33. typedef ex::container_source<string> string_source;
  34. typedef std::vector< std::string > string_list;
  35.  
  36. struct Point {float x, y , z; };
  37. std::vector<int>faces;
  38. std::vector<Point>points;
  39. //Turn on FileReader
  40. bool FileReader = false;
  41.  
  42. float
  43. leftandright = 0.0,
  44. upanddown = 0.0,
  45. forwardandbackward = 0.0;
  46. GLuint vertexbuffer;
  47.  
  48. ///////////////////////////
  49. //DEFINES
  50. ///////////////////////////
  51. #define SCREEN_WIDTH 1240
  52. #define SCREEN_HEIGHT 960
  53. #define BPP 32
  54. #define GL_GLEXT_PROTOTYPES
  55. #define printOpenGLError() printOglError(__FILE__, __LINE__)
  56.  
  57. int printOglError(char *file, int line)
  58. {
  59.  
  60. GLenum glErr;
  61. int retCode = 0;
  62.  
  63. glErr = glGetError();
  64. if (glErr != GL_NO_ERROR)
  65. {
  66. printf("glError in file %s @ line %d: %s\n",
  67. file, line, gluErrorString(glErr));
  68. retCode = 1;
  69. }
  70. return retCode;
  71. }
  72.  
  73. ///////////////////////////
  74.  
  75. ////////////////////////////
  76. //Other Header Files
  77. ///////////////////////////
  78. #include "SurfaceStorage.h"
  79. #include "IndexAssignerFunction.h"
  80. //////////////////////////
  81.  
  82. ////////////////////////
  83. //Global Variables
  84. ////////////////////////
  85.  
  86. /////////////////////////
  87.  
  88. bool MoveObjVertex = false;
  89. bool modelloader = true;
  90.  
  91.  
  92.  
  93. float* point=reinterpret_cast<float*>(&points[0]);
  94. int num_bytes = points.size() * sizeof(points[0]);
  95. GLuint matrixuniform;
  96.  
  97. GLuint vao[2];
  98.  
  99. GLuint translation;
  100. GLuint xvalue = 600.0f;
  101. GLuint objvbo;
  102. GLuint objtextureID;
  103. GLuint ModelTexture;
  104.  
  105.  
  106.  
  107. /////////////////
  108. //EVENT CREATION
  109. ////////////////
  110.  
  111. //SDL Event
  112. SDL_Event event;
  113.  
  114. int counter = 0;
  115. int indexID;
  116.  
  117. float xm;
  118. float ym;
  119.  
  120. int length;
  121. char * buffer;
  122.  
  123.  
  124. static GLfloat TranslationMatrix[] = {
  125.  
  126. 1.0, 0.0, 0.0, 0.0,
  127. 0.0, 1.0, 0.0, 0.0,
  128. 0.0, 0.0, 1.0, 0.0,
  129. 0.0, 0.0, 0.0, 1.0
  130.  
  131.  
  132. };
  133.  
  134.  
  135. //Obj Graphic
  136. static const GLfloat ObjGraphicVertices[] = {
  137. //x y z
  138. 200.0f, 720.0f, 0.0f, 1.0f, 1.0f, 0.0f,
  139. 320.0f, 720.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  140. 320.0f, 640.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  141. 200.0f, 640.0f, 0.0f, 1.0f, 1.0f, 1.0f
  142.  
  143. };
  144.  
  145.  
  146.  
  147. ////////////////////////
  148.  
  149. ///////////////////////
  150. //Structure Rectangle
  151. //////////////////////
  152.  
  153. struct rectangle
  154. {
  155.  
  156. GLuint textureID;
  157. GLuint vbo;
  158. GLfloat matrix[16];
  159.  
  160. };
  161.  
  162. //////////////////////
  163. //Rectangle Variables
  164. /////////////////////
  165.  
  166. //////////////////////
  167. rectangle menubar;
  168. rectangle MainToolBox;
  169. rectangle BoxStorage;
  170. rectangle MenuContext;
  171. rectangle boxstorage;
  172. rectangle ObjGraphic;
  173. //////////////////////
  174.  
  175. glm::mat4 ortho;
  176.  
  177. ///////////////////////////////////
  178. //Prototypes
  179. //////////////////////////////////
  180. void create_rectangle(const char * const path, rectangle *r, const GLfloat *vertices, size_t byte_count, const GLfloat * transformation);
  181. void draw_rectangle(rectangle *r, const float *TranslationMatrix);
  182. void render_rectangle(void);
  183. void setup_sdl_glew (void);
  184. GLuint LoadProgram(const char * const vertex_file_path, const char * Fragment_file_path);
  185. int load_texture(const char * const path);
  186. void draw (void);
  187. /////////////////////////////////
  188.  
  189. //////////////////////////
  190. //Setup Vbo Function
  191. /////////////////////////
  192. void setup_vbos(void)
  193. {
  194.  
  195. ///////////////////
  196. //Vertex Cordinates
  197. ///////////////////
  198.  
  199. ////////////////////////////
  200. //Graphical User Interface
  201. ///////////////////////////
  202.  
  203. //1240 by 960
  204.  
  205.  
  206. //Start GUI Cordinates x y z w - NEEDS TEX CORDS
  207. static const GLfloat GUIVertices[] = {
  208.  
  209. //ToolBar
  210. 1240.0f, 960.0f, 0.0f, 1.0f, 1.0f, 0.0f,
  211. -1.0f, 960.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  212. -1.0f, 930.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  213. 1240.0f, 930.0f, 0.0f, 1.0f, 1.0f, 1.0f
  214.  
  215. };
  216.  
  217. static const GLfloat MainToolBoxVertices[] = {
  218.  
  219. //Main ToolBox
  220. // x y z w X Y
  221. 1240.0f, 120.0f, 0.0f, 1.0f, 1.0f, 0.0f,
  222. -1.0f, 120.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  223. -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  224. 1240.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f
  225.  
  226. };
  227.  
  228. //Menu Context
  229. static const GLfloat MenuContextVertices[] = {
  230.  
  231. // x y z w X Y
  232. -0.76f, 0.94f, 0.0f, 1.0f, 1.0f, 0.0f,
  233. -1.10f, 0.94f, 0.0f, 1.0f, 0.0f, 0.0f,
  234. -1.10f, 0.60f, 0.0f, 1.0f, 0.0f, 1.0f,
  235. -0.76f, 0.60f, 0.0f, 1.0f, 1.0f, 1.0f
  236.  
  237. };
  238.  
  239. //Box Storage
  240. static const GLfloat BoxStorageVertices[] = {
  241.  
  242. 1112.0f, 860.0f, 0.0f, 1.0f, 1.0f, 0.0f,
  243. 120.0f, 860.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  244. 120.0f, 200.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  245. 1112.0f, 200.0f, 0.0f, 1.0f, 1.0f, 1.0f
  246.  
  247. };
  248.  
  249. ////////////////////////////////
  250. //Generate Vertex Array Object
  251. /////////////////////////////////
  252.  
  253. glGenVertexArrays(1, &vao[0]);
  254.  
  255. create_rectangle("GUI/FileMenu.tga", &menubar, GUIVertices, sizeof(GUIVertices), NULL);
  256. create_rectangle("GUI/MainToolBox.tga", &MainToolBox, MainToolBoxVertices, sizeof(MainToolBoxVertices), NULL);
  257. create_rectangle("GUI/MenuContext.tga", &MenuContext, MenuContextVertices, sizeof(MenuContextVertices), NULL);
  258. create_rectangle("GUI/BoxStorage.tga", &boxstorage, BoxStorageVertices, sizeof(BoxStorageVertices), NULL);
  259. create_rectangle("GUI/ObjGraphic.tga", &ObjGraphic, ObjGraphicVertices, sizeof(ObjGraphicVertices), NULL);
  260.  
  261. }
  262.  
  263.  
  264.  
  265. //LOAD SHADER FUNCTION
  266. GLuint LoadProgram(const char * const vertex_file_path, const char * Fragment_file_path){
  267.  
  268. GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
  269. GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  270.  
  271. //READ THE VERTEX SHADER CODE
  272. string VertexShaderCode;
  273. ifstream VertexShaderStream(vertex_file_path, std::ios::in);
  274. if(VertexShaderStream.is_open())
  275. {
  276. string Line = "";
  277. while(getline(VertexShaderStream, Line))
  278. VertexShaderCode += "\n" + Line;
  279. VertexShaderStream.close();
  280. }
  281.  
  282. //READ THE FRAGMENT SHADER CODE
  283. string FragmentShaderCode;
  284. ifstream FragmentShaderStream(Fragment_file_path, std::ios::in);
  285. if(FragmentShaderStream.is_open())
  286. {
  287.  
  288. string Line = "";
  289. while(getline(FragmentShaderStream, Line))
  290. FragmentShaderCode += "\n" + Line;
  291. FragmentShaderStream.close();
  292.  
  293. }
  294.  
  295. GLint Result = GL_FALSE;
  296. int InfoLogLength;
  297.  
  298. //Compile Vertex Shader
  299. printf("Compiling Shader : %s\n", vertex_file_path);
  300. char const * VertexSourcePointer = VertexShaderCode.c_str();
  301. glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
  302. glCompileShader(VertexShaderID);
  303.  
  304. //Check Vertex Shader
  305. glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
  306. glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  307. vector<char> VertexShaderErrorMessage(InfoLogLength);
  308. glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
  309. fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);
  310.  
  311. //Compile Fragment Shader
  312. printf("Compiling Shader : %s\n", Fragment_file_path);
  313. char const * FragmentSourcePointer = FragmentShaderCode.c_str();
  314. glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
  315. glCompileShader(FragmentShaderID);
  316.  
  317. //Check Fragment Shader
  318. glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
  319. glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  320. vector<char> FragmentShaderErrorMessage(InfoLogLength);
  321. glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
  322. fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
  323.  
  324. fprintf(stdout, "Linking Program\n");
  325. GLuint ProgramID = glCreateProgram();
  326.  
  327. //Bind Attribute
  328. glBindAttribLocation(ProgramID, 0, "position");
  329. glBindAttribLocation(ProgramID, 1, "Texcoord0");
  330.  
  331. //Link The Program
  332. glAttachShader(ProgramID, VertexShaderID);
  333. glAttachShader(ProgramID, FragmentShaderID);
  334. glLinkProgram(ProgramID);
  335.  
  336. GLuint texture1;
  337.  
  338.  
  339. texture1 = glGetUniformLocation(ProgramID, "myTextureSampler");
  340. matrixuniform = glGetUniformLocation(ProgramID, "myMatrix");
  341. translation = glGetUniformLocation(ProgramID, "TranslationMatrix");
  342.  
  343.  
  344. //Check The Program
  345. glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
  346. glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  347. vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
  348. fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);
  349.  
  350. //Delete Shader
  351. glDeleteShader(VertexShaderID);
  352. glDeleteShader(FragmentShaderID);
  353.  
  354. glUseProgram(ProgramID);
  355.  
  356. //Return ProgramID
  357. return ProgramID;
  358. }
  359.  
  360. /////////////////////////////////
  361. //Create Rectangle Function
  362. /////////////////////////////////
  363. void create_rectangle(const char * const path, rectangle *r, const GLfloat *vertices, size_t byte_count, const GLfloat * transformation)
  364. {
  365.  
  366. glGenBuffers(1, &r->vbo);
  367. glBindBuffer(GL_ARRAY_BUFFER, r->vbo);
  368. glBufferData(GL_ARRAY_BUFFER, byte_count, vertices, GL_DYNAMIC_DRAW);
  369. r->textureID = load_texture(path);
  370.  
  371. }
  372.  
  373. void draw_rectangle(rectangle *r, const float *TranslationMatrix)
  374. {
  375.  
  376. /////////////////////////////////////////////////////
  377. //Object Graphic <Vertex Attributes/Bindings/Drawing>
  378. /////////////////////////////////////////////////////
  379.  
  380. //Bind array buffer to Vertex Buffer Object
  381. glBindBuffer(GL_ARRAY_BUFFER, r->vbo);
  382.  
  383. // "Bind" the newly created texture : all future texture functions will modify this texture
  384. glBindTexture(GL_TEXTURE_2D, r->textureID);
  385.  
  386. //MenuContext Vertices cordinates
  387. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(0 * sizeof(float)));
  388.  
  389. //MenuContext Texture cordinates
  390. glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(4 * sizeof(float)));
  391.  
  392. //Enable Attribute for "index 1"
  393. glEnableVertexAttribArray(0);
  394.  
  395. //Enable Attribute for "index 1"
  396. glEnableVertexAttribArray(1);
  397.  
  398. //Get Matrix Values/Matrix
  399. glUniformMatrix4fv(matrixuniform, 1, TRUE, r->matrix);
  400.  
  401. glUniformMatrix4fv(matrixuniform, 1, GL_FALSE, glm::value_ptr(ortho));
  402.  
  403. glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);
  404.  
  405. glDrawArrays(GL_QUADS, 0, 4);
  406.  
  407. //END OF MOVE OBJ VERTEX
  408.  
  409. }
  410.  
  411. //Setup SDL/GLEW
  412. void setup_sdl_glew (void)
  413. {
  414. /////////////////////////////////////////////////////////////////////////////////////////////////
  415.  
  416. //////////////////
  417. //SDL SETUP
  418. /////////////////
  419.  
  420. //ENABLE SDL
  421. SDL_Init(SDL_INIT_EVERYTHING);
  422.  
  423. //SCREEN POSITION
  424. SDL_putenv("SDL_VIDEO_CENTERED=center");
  425.  
  426. //SCREEN SETUP
  427. Screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,BPP,SDL_OPENGL|SDL_DOUBLEBUF);
  428.  
  429. ortho = glm::ortho(0.0f, (float)SCREEN_WIDTH, 0.0f, (float)SCREEN_HEIGHT);
  430.  
  431. //////////////////
  432. //GLEW SETUP
  433. /////////////////
  434.  
  435. //GLEW SETUP
  436. GLenum err = glewInit();
  437. glGetError();
  438.  
  439. //GLEW ERROR CHECKING
  440. if (GLEW_OK != err)
  441. {
  442. /* Problem: GlewInit failed, something is seriously wrong. */
  443. fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
  444.  
  445. }
  446. fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
  447. /////////////////////////////////////////////////////////////////////////////////////
  448.  
  449. }
  450.  
  451. ///////////////////////
  452. //ON AND OFF SWITCHES
  453. //////////////////////
  454.  
  455. //ON AND OFF SWITCHES FOR APPLICATION
  456. bool done = false;
  457.  
  458. bool MenuContextToggle = false;
  459.  
  460. bool BoxStorageToggle = false;
  461.  
  462. bool ObjGraphicToggle = false;
  463.  
  464. //Load Texture
  465. int load_texture(const char * const path)
  466. {
  467.  
  468. GLuint textureID;
  469.  
  470. SDL_Surface *surface = IMG_Load(path);
  471.  
  472. // Create one OpenGL textureID
  473. glGenTextures(1, &textureID);
  474.  
  475. // "Bind" the newly created textureID : all future textureID functions will modify r textureID
  476. glBindTexture(GL_TEXTURE_2D, textureID);
  477.  
  478. // Give the image to OpenGL
  479. glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, surface->w,surface->h, 0, GL_BGR, GL_UNSIGNED_BYTE, surface->pixels);
  480.  
  481. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  482. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  483.  
  484. SDL_FreeSurface(surface);
  485.  
  486. return textureID;
  487. }
  488.  
  489. //Draw Function for arrays <VERTEX POSITION DRAWING>
  490. void draw (void)
  491. {
  492. draw_rectangle(&menubar, TranslationMatrix);
  493. draw_rectangle(&MainToolBox, TranslationMatrix);
  494.  
  495. }
  496.  
  497.  
  498.  
  499.  
  500. void ModelLoad(const char * path, int Index)
  501. {
  502.  
  503. }
  504.  
  505.  
  506. //Main Entry Point
  507. int main(int argc , char *argv[])
  508. {
  509.  
  510.  
  511.  
  512. /////////////////
  513. //SETUP
  514. ////////////////
  515.  
  516. //SDL and Glew
  517. setup_sdl_glew();
  518.  
  519. /////////////////
  520.  
  521. objsurface = IMG_Load("GUI/ObjGraphic.tga");
  522. ModelSurface = IMG_Load("GUI/Textures/model.tga");
  523.  
  524. //Keyboard Setup
  525. Uint8 *keystate = SDL_GetKeyState(NULL);
  526.  
  527. SDL_EnableKeyRepeat(100, SDL_DEFAULT_REPEAT_INTERVAL);
  528.  
  529. //Setup Vertex Buffer Object
  530. setup_vbos();
  531.  
  532.  
  533.  
  534. /////////////////////////////
  535. // OpenGL - Viewport Setup
  536. /////////////////////////////
  537.  
  538. //Clear Color
  539. glClearColor(0.0,0.0,1.0,0.0);
  540.  
  541. //View Port Setup
  542. glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  543.  
  544. ////////////////////////////////////////////////////////////////////////////////////////////////////
  545.  
  546. ////////////////
  547. //Load Shaders
  548. ////////////////
  549.  
  550. //Load Shader Program
  551. LoadProgram("graphicaluserinterface.v", "graphicaluserinterface.f");
  552.  
  553. ////////////////////////////////////////////////////////////////////////////////////////////////////
  554.  
  555. int Mouse_X, Mouse_Y;
  556.  
  557. glGenTextures(1, &ModelTexture);
  558.  
  559. glBindTexture(GL_TEXTURE_2D, ModelTexture);
  560.  
  561. glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, ModelSurface->w, ModelSurface->h, 0, GL_BGR, GL_UNSIGNED_BYTE, ModelSurface->pixels);
  562.  
  563. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  564. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  565.  
  566. glGenBuffers(1, &vertexbuffer);
  567.  
  568. glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  569.  
  570. glBufferData(GL_ARRAY_BUFFER, num_bytes, points.data(), GL_STATIC_DRAW);
  571.  
  572.  
  573. //Main While Loop
  574. while(!done)
  575. {
  576. //Get the X and Y Positions on Mouse Cursor and put it into Storage
  577. SDL_GetMouseState(&Mouse_X,&Mouse_Y);
  578.  
  579.  
  580. //Clear
  581. glClear(GL_COLOR_BUFFER_BIT);
  582.  
  583. //Logic
  584.  
  585. //draw <Basic GUI>
  586. draw();
  587.  
  588.  
  589.  
  590. if(BoxStorageToggle == true)
  591. {
  592.  
  593. draw_rectangle(&boxstorage, TranslationMatrix);
  594.  
  595. //////////////////////////////
  596. //Directory Reading Proccess
  597. /////////////////////////////
  598.  
  599. //File Path
  600. path p("Box Storage");
  601.  
  602. //String vector container
  603. std::vector < std::string > list;
  604.  
  605. ////////////////////////////
  606.  
  607. //Iteration Loop
  608. try
  609. {
  610. for (directory_iterator it(p); it != directory_iterator(); ++it)
  611. {
  612.  
  613. //Output it contents to CMD window
  614. // cout << *it << endl;
  615.  
  616. //find the it path names store it in s
  617. string s = (*it).path().string();
  618.  
  619. //then push back list
  620. list.push_back( s );
  621.  
  622. }
  623.  
  624. }
  625.  
  626. catch (const filesystem_error& ex)
  627. {
  628. // cout << ex.what() << endl;
  629. }
  630.  
  631. //Float Containers
  632. float row=0,column=0;
  633. float quad_width = -146.0f , quad_height = -100.0f;
  634.  
  635. //iteration Loop
  636. for(int i=0;i<list.size();++i)
  637. {
  638. //if list is not at its full capacity
  639. if(list[i].find(".obj") != std::string::npos)
  640. {
  641. //every 6th quad, change row
  642. if(i % 6 == 0)
  643. {
  644. //beginning of a row
  645. column = 0;
  646.  
  647. //row iteration
  648. ++row;
  649. }
  650.  
  651. //Translation Process
  652. GLfloat TranslationMatrix[] = {
  653. 1.0, 0.0, 0.0, 720.0+column*quad_width,
  654. 0.0, 1.0, 0.0, 82.0+row*quad_height,
  655. 0.0, 0.0, 1.0, 0.0,
  656. 0.0, 0.0, 0.0, 1.0
  657. };
  658.  
  659. //Send Translation Matrix up to the vertex shader
  660. glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);
  661.  
  662. //Draw Rectangle to frustum
  663. draw_rectangle(&ObjGraphic, TranslationMatrix);
  664. }
  665.  
  666. //column itearation
  667. ++column;
  668.  
  669.  
  670.  
  671. //Index Assigners
  672. if(event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_BUTTON_LEFT))
  673. {
  674. //use Index Assigner
  675. int index = IndexAssigner(1, 1);
  676.  
  677. //make a fileobject and store list and the index of that list in a c string
  678. ifstream file (list[index].c_str() );
  679.  
  680. //Make another string
  681. //string line;
  682.  
  683. points.push_back(Point());
  684. Point p;
  685.  
  686. int face[4];
  687. //While FileObject not equal end of file
  688. while (!file.eof() )
  689. {
  690.  
  691.  
  692. char modelbuffer[10000];
  693.  
  694. //Get lines and store it in line string
  695. //getline(file, line);
  696.  
  697. file.getline(modelbuffer, 10000);
  698.  
  699.  
  700. switch(modelbuffer[0])
  701. {
  702.  
  703. case 'v' :
  704.  
  705. sscanf(modelbuffer, "v %f %f %f", &p.x, &p.y, &p.z);
  706.  
  707.  
  708.  
  709. points.push_back(p);
  710.  
  711. break;
  712.  
  713.  
  714.  
  715. case 'f':
  716. sscanf(modelbuffer, "f %d %d %d %d", face, face+1, face+2, face+3 );
  717.  
  718.  
  719.  
  720.  
  721. faces.push_back(face[0] - 1);
  722. faces.push_back(face[1] - 1);
  723. faces.push_back(face[2] - 1);
  724. faces.push_back(face[3] - 1);
  725. break;
  726. }
  727.  
  728. //Turn on FileReader
  729. FileReader = true;
  730.  
  731.  
  732. }
  733.  
  734. }
  735.  
  736. }
  737.  
  738. }
  739.  
  740.  
  741. //If File Reader is On
  742. if(FileReader == true)
  743. {
  744.  
  745. glBindTexture(GL_TEXTURE_2D, ModelTexture);
  746.  
  747. glEnableVertexAttribArray(3);
  748.  
  749. glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  750.  
  751. glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE,0 ,0);
  752.  
  753.  
  754. //Translation Process
  755. GLfloat TranslationMatrix[] = {
  756. 1.0, 0.0, 0.0, 0.0,
  757. 0.0, 1.0, 0.0, 0.0,
  758. 0.0, 0.0, 0.0, 0.0,
  759. 0.0, 0.0, 0.0, 1.0
  760. };
  761.  
  762. //Send Translation Matrix up to the vertex shader
  763. glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);
  764.  
  765.  
  766. //THIS IS FINE
  767. //glDrawElements(GL_QUADS, points.size(), GL_UNSIGNED_INT, points.data());
  768. glDrawElements( GL_QUADS, faces.size(), GL_UNSIGNED_INT, faces.data());
  769.  
  770.  
  771. }
  772.  
  773.  
  774.  
  775. //Turn of Menu Context Toggle
  776. if(keystate[SDLK_SPACE])
  777. {
  778.  
  779. MenuContextToggle = false;
  780.  
  781. }
  782.  
  783. //Turn on Box Storage
  784. if(keystate[SDLK_b])
  785. {
  786.  
  787. BoxStorageToggle = true;
  788.  
  789. }
  790.  
  791.  
  792.  
  793.  
  794. /////////////////////////////////////////////////////////////////
  795.  
  796. ///////////////////////
  797. //Menu Context <SETUP>
  798. //////////////////////
  799.  
  800. ///////////////////////////////////////////////////////////////
  801.  
  802. //SDL EVENT QUEUE
  803. while(SDL_PollEvent(&event))
  804. {
  805. switch(event.type)
  806. {
  807.  
  808. //if User Presses Quit Button
  809. case SDL_QUIT:
  810. return 0;
  811. break;
  812.  
  813. /////////////////////////////////////////////
  814.  
  815. ////////////////
  816. //MOUSE EVENTS
  817. ///////////////
  818.  
  819. case SDL_MOUSEBUTTONDOWN:
  820.  
  821. if(Mouse_X <= 15, Mouse_Y <= 30)
  822. {
  823.  
  824. MenuContextToggle = true;
  825.  
  826. }
  827.  
  828. ///////////////////////////////////////////////
  829.  
  830. }
  831.  
  832. }
  833. //Update
  834. SDL_GL_SwapBuffers();
  835. }
  836.  
  837. }
  838. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:18: error: glew.h: No such file or directory
prog.cpp:6:21: error: SDL/SDL.H: No such file or directory
prog.cpp:7:28: error: SDL/SDL_IMAGE.H: No such file or directory
prog.cpp:8:28: error: SDL/SDL_OPENGL.H: No such file or directory
prog.cpp:15:55: error: libs/iostreams/example/container_device.hpp: No such file or directory
prog.cpp:21:20: error: GL/glu.h: No such file or directory
prog.cpp:22:24: error: glm/glm.hpp: No such file or directory
prog.cpp:23:33: error: glm/gtc/type_ptr.hpp: No such file or directory
prog.cpp:24:41: error: glm/gtc/matrix_transform.hpp: No such file or directory
prog.cpp:78:28: error: SurfaceStorage.h: No such file or directory
prog.cpp:79:35: error: IndexAssignerFunction.h: No such file or directory
prog.cpp:29: error: ‘example’ is not a namespace-name
prog.cpp:29: error: expected namespace-name before ‘;’ token
prog.cpp:33: error: ‘ex’ has not been declared
prog.cpp:33: error: expected initializer before ‘<’ token
prog.cpp:46: error: ‘GLuint’ does not name a type
prog.cpp: In function ‘int printOglError(char*, int)’:
prog.cpp:60: error: ‘GLenum’ was not declared in this scope
prog.cpp:60: error: expected `;' before ‘glErr’
prog.cpp:63: error: ‘glErr’ was not declared in this scope
prog.cpp:63: error: ‘glGetError’ was not declared in this scope
prog.cpp:64: error: ‘GL_NO_ERROR’ was not declared in this scope
prog.cpp:67: error: ‘gluErrorString’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:95: error: ‘GLuint’ does not name a type
prog.cpp:97: error: ‘GLuint’ does not name a type
prog.cpp:99: error: ‘GLuint’ does not name a type
prog.cpp:100: error: ‘GLuint’ does not name a type
prog.cpp:101: error: ‘GLuint’ does not name a type
prog.cpp:102: error: ‘GLuint’ does not name a type
prog.cpp:103: error: ‘GLuint’ does not name a type
prog.cpp:112: error: ‘SDL_Event’ does not name a type
prog.cpp:124: error: ‘GLfloat’ does not name a type
prog.cpp:136: error: ‘GLfloat’ does not name a type
prog.cpp:156: error: ‘GLuint’ does not name a type
prog.cpp:157: error: ‘GLuint’ does not name a type
prog.cpp:158: error: ‘GLfloat’ does not name a type
prog.cpp:175: error: ‘glm’ has not been declared
prog.cpp:175: error: expected constructor, destructor, or type conversion before ‘ortho’
prog.cpp:180: error: expected ‘,’ or ‘...’ before ‘*’ token
prog.cpp:180: error: ISO C++ forbids declaration of ‘GLfloat’ with no type
prog.cpp:184: error: ‘GLuint’ does not name a type
prog.cpp: In function ‘void setup_vbos()’:
prog.cpp:207: error: ‘GLfloat’ does not name a type
prog.cpp:217: error: ‘GLfloat’ does not name a type
prog.cpp:229: error: ‘GLfloat’ does not name a type
prog.cpp:240: error: ‘GLfloat’ does not name a type
prog.cpp:253: error: ‘vao’ was not declared in this scope
prog.cpp:253: error: ‘glGenVertexArrays’ was not declared in this scope
prog.cpp:255: error: ‘GUIVertices’ was not declared in this scope
prog.cpp:256: error: ‘MainToolBoxVertices’ was not declared in this scope
prog.cpp:257: error: ‘MenuContextVertices’ was not declared in this scope
prog.cpp:258: error: ‘BoxStorageVertices’ was not declared in this scope
prog.cpp:259: error: ‘ObjGraphicVertices’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:266: error: ‘GLuint’ does not name a type
prog.cpp:363: error: expected ‘,’ or ‘...’ before ‘*’ token
prog.cpp:363: error: ISO C++ forbids declaration of ‘GLfloat’ with no type
prog.cpp: In function ‘void create_rectangle(const char*, rectangle*, int)’:
prog.cpp:366: error: ‘struct rectangle’ has no member named ‘vbo’
prog.cpp:366: error: ‘glGenBuffers’ was not declared in this scope
prog.cpp:367: error: ‘GL_ARRAY_BUFFER’ was not declared in this scope
prog.cpp:367: error: ‘struct rectangle’ has no member named ‘vbo’
prog.cpp:367: error: ‘glBindBuffer’ was not declared in this scope
prog.cpp:368: error: ‘byte_count’ was not declared in this scope
prog.cpp:368: error: ‘vertices’ was not declared in this scope
prog.cpp:368: error: ‘GL_DYNAMIC_DRAW’ was not declared in this scope
prog.cpp:368: error: ‘glBufferData’ was not declared in this scope
prog.cpp:369: error: ‘struct rectangle’ has no member named ‘textureID’
prog.cpp: In function ‘void draw_rectangle(rectangle*, const float*)’:
prog.cpp:381: error: ‘GL_ARRAY_BUFFER’ was not declared in this scope
prog.cpp:381: error: ‘struct rectangle’ has no member named ‘vbo’
prog.cpp:381: error: ‘glBindBuffer’ was not declared in this scope
prog.cpp:384: error: ‘GL_TEXTURE_2D’ was not declared in this scope
prog.cpp:384: error: ‘struct rectangle’ has no member named ‘textureID’
prog.cpp:384: error: ‘glBindTexture’ was not declared in this scope
prog.cpp:387: error: ‘GL_FLOAT’ was not declared in this scope
prog.cpp:387: error: ‘GL_FALSE’ was not declared in this scope
prog.cpp:387: error: ISO C++ forbids declaration of ‘type name’ with no type
prog.cpp:387: error: expected `>' before ‘GLvoid’
prog.cpp:387: error: expected `(' before ‘GLvoid’
prog.cpp:387: error: ‘GLvoid’ was not declared in this scope
prog.cpp:387: error: expected primary-expression before ‘>’ token
prog.cpp:390: error: ISO C++ forbids declaration of ‘type name’ with no type
prog.cpp:390: error: expected `>' before ‘GLvoid’
prog.cpp:390: error: expected `(' before ‘GLvoid’
prog.cpp:390: error: expected primary-expression before ‘>’ token
prog.cpp:393: error: ‘glEnableVertexAttribArray’ was not declared in this scope
prog.cpp:399: error: ‘matrixuniform’ was not declared in this scope
prog.cpp:399: error: ‘TRUE’ was not declared in this scope
prog.cpp:399: error: ‘struct rectangle’ has no member named ‘matrix’
prog.cpp:399: error: ‘glUniformMatrix4fv’ was not declared in this scope
prog.cpp:401: error: ‘glm’ has not been declared
prog.cpp:401: error: ‘ortho’ was not declared in this scope
prog.cpp:403: error: ‘translation’ was not declared in this scope
prog.cpp:405: error: ‘GL_QUADS’ was not declared in this scope
prog.cpp:405: error: ‘glDrawArrays’ was not declared in this scope
prog.cpp: In function ‘void setup_sdl_glew()’:
prog.cpp:421: error: ‘SDL_INIT_EVERYTHING’ was not declared in this scope
prog.cpp:421: error: ‘SDL_Init’ was not declared in this scope
prog.cpp:424: error: ‘SDL_putenv’ was not declared in this scope
prog.cpp:427: error: ‘Screen’ was not declared in this scope
prog.cpp:427: error: ‘SDL_OPENGL’ was not declared in this scope
prog.cpp:427: error: ‘SDL_DOUBLEBUF’ was not declared in this scope
prog.cpp:427: error: ‘SDL_SetVideoMode’ was not declared in this scope
prog.cpp:429: error: ‘ortho’ was not declared in this scope
prog.cpp:429: error: ‘glm’ has not been declared
prog.cpp:436: error: ‘GLenum’ was not declared in this scope
prog.cpp:436: error: expected `;' before ‘err’
prog.cpp:437: error: ‘glGetError’ was not declared in this scope
prog.cpp:440: error: ‘GLEW_OK’ was not declared in this scope
prog.cpp:440: error: ‘err’ was not declared in this scope
prog.cpp:443: error: ‘glewGetErrorString’ was not declared in this scope
prog.cpp:446: error: ‘GLEW_VERSION’ was not declared in this scope
prog.cpp:446: error: ‘glewGetString’ was not declared in this scope
prog.cpp: In function ‘int load_texture(const char*)’:
prog.cpp:468: error: ‘GLuint’ was not declared in this scope
prog.cpp:468: error: expected `;' before ‘textureID’
prog.cpp:470: error: ‘SDL_Surface’ was not declared in this scope
prog.cpp:470: error: ‘surface’ was not declared in this scope
prog.cpp:470: error: ‘IMG_Load’ was not declared in this scope
prog.cpp:473: error: ‘textureID’ was not declared in this scope
prog.cpp:473: error: ‘glGenTextures’ was not declared in this scope
prog.cpp:476: error: ‘GL_TEXTURE_2D’ was not declared in this scope
prog.cpp:476: error: ‘glBindTexture’ was not declared in this scope
prog.cpp:479: error: ‘GL_RGBA’ was not declared in this scope
prog.cpp:479: error: ‘GL_BGR’ was not declared in this scope
prog.cpp:479: error: ‘GL_UNSIGNED_BYTE’ was not declared in this scope
prog.cpp:479: error: ‘glTexImage2D’ was not declared in this scope
prog.cpp:481: error: ‘GL_TEXTURE_MIN_FILTER’ was not declared in this scope
prog.cpp:481: error: ‘GL_NEAREST’ was not declared in this scope
prog.cpp:481: error: ‘glTexParameteri’ was not declared in this scope
prog.cpp:482: error: ‘GL_TEXTURE_MAG_FILTER’ was not declared in this scope
prog.cpp:484: error: ‘SDL_FreeSurface’ was not declared in this scope
prog.cpp: In function ‘void draw()’:
prog.cpp:492: error: ‘TranslationMatrix’ was not declared in this scope
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:521: error: ‘objsurface’ was not declared in this scope
prog.cpp:521: error: ‘IMG_Load’ was not declared in this scope
prog.cpp:522: error: ‘ModelSurface’ was not declared in this scope
prog.cpp:525: error: ‘Uint8’ was not declared in this scope
prog.cpp:525: error: ‘keystate’ was not declared in this scope
prog.cpp:525: error: ‘SDL_GetKeyState’ was not declared in this scope
prog.cpp:527: error: ‘SDL_DEFAULT_REPEAT_INTERVAL’ was not declared in this scope
prog.cpp:527: error: ‘SDL_EnableKeyRepeat’ was not declared in this scope
prog.cpp:539: error: ‘glClearColor’ was not declared in this scope
prog.cpp:542: error: ‘glViewport’ was not declared in this scope
prog.cpp:551: error: ‘LoadProgram’ was not declared in this scope
prog.cpp:557: error: ‘ModelTexture’ was not declared in this scope
prog.cpp:557: error: ‘glGenTextures’ was not declared in this scope
prog.cpp:559: error: ‘GL_TEXTURE_2D’ was not declared in this scope
prog.cpp:559: error: ‘glBindTexture’ was not declared in this scope
prog.cpp:561: error: ‘GL_RGBA’ was not declared in this scope
prog.cpp:561: error: ‘GL_BGR’ was not declared in this scope
prog.cpp:561: error: ‘GL_UNSIGNED_BYTE’ was not declared in this scope
prog.cpp:561: error: ‘glTexImage2D’ was not declared in this scope
prog.cpp:563: error: ‘GL_TEXTURE_MIN_FILTER’ was not declared in this scope
prog.cpp:563: error: ‘GL_NEAREST’ was not declared in this scope
prog.cpp:563: error: ‘glTexParameteri’ was not declared in this scope
prog.cpp:564: error: ‘GL_TEXTURE_MAG_FILTER’ was not declared in this scope
prog.cpp:566: error: ‘vertexbuffer’ was not declared in this scope
prog.cpp:566: error: ‘glGenBuffers’ was not declared in this scope
prog.cpp:568: error: ‘GL_ARRAY_BUFFER’ was not declared in this scope
prog.cpp:568: error: ‘glBindBuffer’ was not declared in this scope
prog.cpp:570: error: ‘GL_STATIC_DRAW’ was not declared in this scope
prog.cpp:570: error: ‘glBufferData’ was not declared in this scope
prog.cpp:577: error: ‘SDL_GetMouseState’ was not declared in this scope
prog.cpp:581: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
prog.cpp:581: error: ‘glClear’ was not declared in this scope
prog.cpp:593: error: ‘TranslationMatrix’ was not declared in this scope
prog.cpp:636: warning: comparison between signed and unsigned integer expressions
prog.cpp:652: error: ‘GLfloat’ was not declared in this scope
prog.cpp:652: error: expected `;' before ‘TranslationMatrix’
prog.cpp:660: error: ‘translation’ was not declared in this scope
prog.cpp:660: error: ‘TRUE’ was not declared in this scope
prog.cpp:660: error: ‘glUniformMatrix4fv’ was not declared in this scope
prog.cpp:672: error: ‘event’ was not declared in this scope
prog.cpp:672: error: ‘SDL_MOUSEBUTTONDOWN’ was not declared in this scope
prog.cpp:672: error: ‘SDL_BUTTON_LEFT’ was not declared in this scope
prog.cpp:672: error: ‘SDL_BUTTON’ was not declared in this scope
prog.cpp:675: error: ‘IndexAssigner’ was not declared in this scope
prog.cpp:633: warning: unused variable ‘quad_width’
prog.cpp:633: warning: unused variable ‘quad_height’
prog.cpp:747: error: ‘glEnableVertexAttribArray’ was not declared in this scope
prog.cpp:751: error: ‘GL_FLOAT’ was not declared in this scope
prog.cpp:751: error: ‘GL_FALSE’ was not declared in this scope
prog.cpp:751: error: ‘glVertexAttribPointer’ was not declared in this scope
prog.cpp:755: error: ‘GLfloat’ was not declared in this scope
prog.cpp:755: error: expected `;' before ‘TranslationMatrix’
prog.cpp:763: error: ‘translation’ was not declared in this scope
prog.cpp:763: error: ‘TRUE’ was not declared in this scope
prog.cpp:763: error: ‘TranslationMatrix’ was not declared in this scope
prog.cpp:763: error: ‘glUniformMatrix4fv’ was not declared in this scope
prog.cpp:768: error: ‘GL_QUADS’ was not declared in this scope
prog.cpp:768: error: ‘GL_UNSIGNED_INT’ was not declared in this scope
prog.cpp:768: error: ‘glDrawElements’ was not declared in this scope
prog.cpp:776: error: ‘SDLK_SPACE’ was not declared in this scope
prog.cpp:784: error: ‘SDLK_b’ was not declared in this scope
prog.cpp:803: error: ‘event’ was not declared in this scope
prog.cpp:803: error: ‘SDL_PollEvent’ was not declared in this scope
prog.cpp:809: error: ‘SDL_QUIT’ was not declared in this scope
prog.cpp:819: error: ‘SDL_MOUSEBUTTONDOWN’ was not declared in this scope
prog.cpp:821: warning: left-hand operand of comma has no effect
prog.cpp:834: error: ‘SDL_GL_SwapBuffers’ was not declared in this scope
stdout
Standard output is empty