Skip to content

Instantly share code, notes, and snippets.

@AmrMKayid
Created October 13, 2018 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmrMKayid/028d1898429b69350da31e7e393ec531 to your computer and use it in GitHub Desktop.
Save AmrMKayid/028d1898429b69350da31e7e393ec531 to your computer and use it in GitHub Desktop.
using ds in cpp OpenGL file
/*
TO COMPILE & RUN
g++ -o out main.cpp -framework GLUT -framework OpenGL -Wno-deprecated && ./out
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
#endif
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
//function for printing the elements in a list
void showlist(list <int> g)
{
list <int> :: iterator it;
for(it = g.begin(); it != g.end(); ++it)
cout << '\t' << *it;
cout << '\n';
}
void Display();
int main(int argc, char** argr) {
glutInit(&argc, argr);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(50, 50);
glutCreateWindow("Lab 01");
glutDisplayFunc(Display);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPointSize(9.0);
//glLineWidth(9.0);
gluOrtho2D(0.0, 1000.0, 0.0, 600.0);
glutMainLoop();
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT);
list <int> gqlist1, gqlist2;
for (int i = 0; i < 10; ++i)
{
gqlist1.push_back(i * 2);
gqlist2.push_front(i * 3);
}
cout << "\nList 1 (gqlist1) is : ";
showlist(gqlist1);
cout << "\nList 2 (gqlist2) is : ";
showlist(gqlist2);
cout << "\ngqlist1.front() : " << gqlist1.front();
cout << "\ngqlist1.back() : " << gqlist1.back();
cout << "\ngqlist1.pop_front() : ";
gqlist1.pop_front();
showlist(gqlist1);
cout << "\ngqlist2.pop_back() : ";
gqlist2.pop_back();
showlist(gqlist2);
cout << "\ngqlist1.reverse() : ";
gqlist1.reverse();
showlist(gqlist1);
cout << "\ngqlist2.sort(): ";
gqlist2.sort();
showlist(gqlist2);
glFlush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment