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. int numfloats = 4;
  93. float* point=reinterpret_cast<float*>(&points[0]);
  94. int num_bytes=numfloats*sizeof(float);
  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. // OpenGL - Viewport Setup
  534. /////////////////////////////
  535.  
  536. //Clear Color
  537. glClearColor(0.0,0.0,1.0,0.0);
  538.  
  539. //View Port Setup
  540. glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  541.  
  542. ////////////////////////////////////////////////////////////////////////////////////////////////////
  543.  
  544. ////////////////
  545. //Load Shaders
  546. ////////////////
  547.  
  548. //Load Shader Program
  549. LoadProgram("graphicaluserinterface.v", "graphicaluserinterface.f");
  550.  
  551. ////////////////////////////////////////////////////////////////////////////////////////////////////
  552.  
  553. int Mouse_X, Mouse_Y;
  554.  
  555. //Main While Loop
  556. while(!done)
  557. {
  558. //Get the X and Y Positions on Mouse Cursor and put it into Storage
  559. SDL_GetMouseState(&Mouse_X,&Mouse_Y);
  560.  
  561.  
  562. //Clear
  563. glClear(GL_COLOR_BUFFER_BIT);
  564.  
  565. //Logic
  566.  
  567. //draw <Basic GUI>
  568. draw();
  569.  
  570. if(BoxStorageToggle == true)
  571. {
  572.  
  573. draw_rectangle(&boxstorage, TranslationMatrix);
  574.  
  575. //////////////////////////////
  576. //Directory Reading Proccess
  577. /////////////////////////////
  578.  
  579. //File Path
  580. path p("Box Storage");
  581.  
  582. //String vector container
  583. std::vector < std::string > list;
  584.  
  585. ////////////////////////////
  586.  
  587. //Iteration Loop
  588. try
  589. {
  590. for (directory_iterator it(p); it != directory_iterator(); ++it)
  591. {
  592.  
  593. //Output it contents to CMD window
  594. // cout << *it << endl;
  595.  
  596. //find the it path names store it in s
  597. string s = (*it).path().string();
  598.  
  599. //then push back list
  600. list.push_back( s );
  601.  
  602. }
  603.  
  604. }
  605.  
  606. catch (const filesystem_error& ex)
  607. {
  608. // cout << ex.what() << endl;
  609. }
  610.  
  611. //Float Containers
  612. float row=0,column=0;
  613. float quad_width = -146.0f , quad_height = -100.0f;
  614.  
  615. //iteration Loop
  616. for(int i=0;i<list.size();++i)
  617. {
  618. //if list is not at its full capacity
  619. if(list[i].find(".obj") != std::string::npos)
  620. {
  621. //every 6th quad, change row
  622. if(i % 6 == 0)
  623. {
  624. //beginning of a row
  625. column = 0;
  626.  
  627. //row iteration
  628. ++row;
  629. }
  630.  
  631. //Translation Process
  632. GLfloat TranslationMatrix[] = {
  633. 1.0, 0.0, 0.0, 720.0+column*quad_width,
  634. 0.0, 1.0, 0.0, 82.0+row*quad_height,
  635. 0.0, 0.0, 1.0, 0.0,
  636. 0.0, 0.0, 0.0, 1.0
  637. };
  638.  
  639. //Send Translation Matrix up to the vertex shader
  640. glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);
  641.  
  642. //Draw Rectangle to frustum
  643. draw_rectangle(&ObjGraphic, TranslationMatrix);
  644. }
  645.  
  646. //column itearation
  647. ++column;
  648.  
  649.  
  650.  
  651. //Index Assigners
  652. if(event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_BUTTON_LEFT))
  653. {
  654. //use Index Assigner
  655. int index = IndexAssigner(1, 1);
  656.  
  657. //make a fileobject and store list and the index of that list in a c string
  658. ifstream file (list[index].c_str() );
  659.  
  660. //Make another string
  661. //string line;
  662.  
  663. points.push_back(Point());
  664. Point p;
  665.  
  666. int face[4];
  667. //While FileObject not equal end of file
  668. while (!file.eof() )
  669. {
  670.  
  671.  
  672. char modelbuffer[10000];
  673.  
  674. //Get lines and store it in line string
  675. //getline(file, line);
  676.  
  677. file.getline(modelbuffer, 10000);
  678.  
  679.  
  680. switch(modelbuffer[0])
  681. {
  682.  
  683. case 'v' :
  684.  
  685. sscanf(modelbuffer, "v %f %f %f", &p.x, &p.y, &p.z);
  686.  
  687.  
  688.  
  689. points.push_back(p);
  690.  
  691. break;
  692.  
  693.  
  694.  
  695. case 'f':
  696. sscanf(modelbuffer, "f %d %d %d %d", face, face+1, face+2, face+3 );
  697.  
  698.  
  699.  
  700.  
  701. faces.push_back(face[0]);
  702. faces.push_back(face[1]);
  703. faces.push_back(face[2]);
  704. faces.push_back(face[3]);
  705.  
  706.  
  707. }
  708.  
  709. //Turn on FileReader
  710. FileReader = true;
  711.  
  712.  
  713. }
  714.  
  715. }
  716.  
  717. }
  718.  
  719. }
  720.  
  721.  
  722. //If File Reader is On
  723. if(FileReader == true)
  724. {
  725.  
  726.  
  727.  
  728.  
  729. glGenBuffers(1, &vertexbuffer);
  730.  
  731. glGenTextures(1, &ModelTexture);
  732.  
  733. glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  734.  
  735. glBindTexture(GL_TEXTURE_3D, ModelTexture);
  736.  
  737. glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, ModelSurface->w, ModelSurface->h, 0, GL_BGR, GL_UNSIGNED_BYTE, ModelSurface->pixels);
  738.  
  739. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  740. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  741.  
  742. glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
  743.  
  744. glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE,num_bytes ,points.data());
  745.  
  746. glEnableVertexAttribArray(3);
  747.  
  748. //Translation Process
  749. GLfloat TranslationMatrix[] = {
  750. 1.0, 0.0, 0.0, 0.0,
  751. 0.0, 1.0, 0.0, 0.0,
  752. 0.0, 0.0, 1.0, 1.0,
  753. 0.0, 0.0, 0.0, 1.0
  754. };
  755.  
  756. //Send Translation Matrix up to the vertex shader
  757. glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);
  758.  
  759.  
  760. //THIS IS FINE
  761. // glDrawElements(GL_QUADS, points.size(), GL_UNSIGNED_INT, points.data());
  762. glDrawElements( GL_QUADS, faces.size(), GL_UNSIGNED_INT, faces.data());
  763.  
  764.  
  765. }
  766.  
  767.  
  768.  
  769. //Turn of Menu Context Toggle
  770. if(keystate[SDLK_SPACE])
  771. {
  772.  
  773. MenuContextToggle = false;
  774.  
  775. }
  776.  
  777. //Turn on Box Storage
  778. if(keystate[SDLK_b])
  779. {
  780.  
  781. BoxStorageToggle = true;
  782.  
  783. }
  784.  
  785.  
  786.  
  787.  
  788. /////////////////////////////////////////////////////////////////
  789.  
  790. ///////////////////////
  791. //Menu Context <SETUP>
  792. //////////////////////
  793.  
  794. ///////////////////////////////////////////////////////////////
  795.  
  796. //SDL EVENT QUEUE
  797. while(SDL_PollEvent(&event))
  798. {
  799. switch(event.type)
  800. {
  801.  
  802. //if User Presses Quit Button
  803. case SDL_QUIT:
  804. return 0;
  805. break;
  806.  
  807. /////////////////////////////////////////////
  808.  
  809. ////////////////
  810. //MOUSE EVENTS
  811. ///////////////
  812.  
  813. case SDL_MOUSEBUTTONDOWN:
  814.  
  815. if(Mouse_X <= 15, Mouse_Y <= 30)
  816. {
  817.  
  818. MenuContextToggle = true;
  819.  
  820. }
  821.  
  822. ///////////////////////////////////////////////
  823.  
  824. }
  825.  
  826. }
  827. //Update
  828. SDL_GL_SwapBuffers();
  829. }
  830.  
  831. }
  832. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
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:537: error: ‘glClearColor’ was not declared in this scope
prog.cpp:540: error: ‘glViewport’ was not declared in this scope
prog.cpp:549: error: ‘LoadProgram’ was not declared in this scope
prog.cpp:559: error: ‘SDL_GetMouseState’ was not declared in this scope
prog.cpp:563: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
prog.cpp:563: error: ‘glClear’ was not declared in this scope
prog.cpp:573: error: ‘TranslationMatrix’ was not declared in this scope
prog.cpp:616: warning: comparison between signed and unsigned integer expressions
prog.cpp:632: error: ‘GLfloat’ was not declared in this scope
prog.cpp:632: error: expected `;' before ‘TranslationMatrix’
prog.cpp:640: error: ‘translation’ was not declared in this scope
prog.cpp:640: error: ‘TRUE’ was not declared in this scope
prog.cpp:640: error: ‘glUniformMatrix4fv’ was not declared in this scope
prog.cpp:652: error: ‘event’ was not declared in this scope
prog.cpp:652: error: ‘SDL_MOUSEBUTTONDOWN’ was not declared in this scope
prog.cpp:652: error: ‘SDL_BUTTON_LEFT’ was not declared in this scope
prog.cpp:652: error: ‘SDL_BUTTON’ was not declared in this scope
prog.cpp:655: error: ‘IndexAssigner’ was not declared in this scope
prog.cpp:613: warning: unused variable ‘quad_width’
prog.cpp:613: warning: unused variable ‘quad_height’
prog.cpp:729: error: ‘vertexbuffer’ was not declared in this scope
prog.cpp:729: error: ‘glGenBuffers’ was not declared in this scope
prog.cpp:731: error: ‘ModelTexture’ was not declared in this scope
prog.cpp:731: error: ‘glGenTextures’ was not declared in this scope
prog.cpp:733: error: ‘GL_ARRAY_BUFFER’ was not declared in this scope
prog.cpp:733: error: ‘glBindBuffer’ was not declared in this scope
prog.cpp:735: error: ‘GL_TEXTURE_3D’ was not declared in this scope
prog.cpp:735: error: ‘glBindTexture’ was not declared in this scope
prog.cpp:737: error: ‘GL_TEXTURE_2D’ was not declared in this scope
prog.cpp:737: error: ‘GL_RGBA’ was not declared in this scope
prog.cpp:737: error: ‘GL_BGR’ was not declared in this scope
prog.cpp:737: error: ‘GL_UNSIGNED_BYTE’ was not declared in this scope
prog.cpp:737: error: ‘glTexImage2D’ was not declared in this scope
prog.cpp:739: error: ‘GL_TEXTURE_MIN_FILTER’ was not declared in this scope
prog.cpp:739: error: ‘GL_NEAREST’ was not declared in this scope
prog.cpp:739: error: ‘glTexParameteri’ was not declared in this scope
prog.cpp:740: error: ‘GL_TEXTURE_MAG_FILTER’ was not declared in this scope
prog.cpp:742: error: ‘GL_STATIC_DRAW’ was not declared in this scope
prog.cpp:742: error: ‘glBufferData’ was not declared in this scope
prog.cpp:744: error: ‘GL_FLOAT’ was not declared in this scope
prog.cpp:744: error: ‘GL_FALSE’ was not declared in this scope
prog.cpp:744: error: ‘glVertexAttribPointer’ was not declared in this scope
prog.cpp:746: error: ‘glEnableVertexAttribArray’ was not declared in this scope
prog.cpp:749: error: ‘GLfloat’ was not declared in this scope
prog.cpp:749: error: expected `;' before ‘TranslationMatrix’
prog.cpp:757: error: ‘translation’ was not declared in this scope
prog.cpp:757: error: ‘TRUE’ was not declared in this scope
prog.cpp:757: error: ‘TranslationMatrix’ was not declared in this scope
prog.cpp:757: error: ‘glUniformMatrix4fv’ was not declared in this scope
prog.cpp:762: error: ‘GL_QUADS’ was not declared in this scope
prog.cpp:762: error: ‘GL_UNSIGNED_INT’ was not declared in this scope
prog.cpp:762: error: ‘glDrawElements’ was not declared in this scope
prog.cpp:770: error: ‘SDLK_SPACE’ was not declared in this scope
prog.cpp:778: error: ‘SDLK_b’ was not declared in this scope
prog.cpp:797: error: ‘event’ was not declared in this scope
prog.cpp:797: error: ‘SDL_PollEvent’ was not declared in this scope
prog.cpp:803: error: ‘SDL_QUIT’ was not declared in this scope
prog.cpp:813: error: ‘SDL_MOUSEBUTTONDOWN’ was not declared in this scope
prog.cpp:815: warning: left-hand operand of comma has no effect
prog.cpp:828: error: ‘SDL_GL_SwapBuffers’ was not declared in this scope
stdout
Standard output is empty