Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. /*
  2.  * gettin_started.cpp
  3.  *
  4.  *  Created on: 03.11.2010
  5.  *      Author: s_inchen
  6.  */
  7. #include <stdlib.h>
  8. #include <GL/gl.h>
  9. #include <GL/glu.h>
  10. #include <GL/glut.h>
  11. #include <vector>
  12. #include "Vector2D.h"
  13. #include <iostream>
  14.  
  15. using namespace std;
  16. //Laufvariable i:
  17. int i = 0;
  18.  
  19. //Fenstergroesse:
  20. const int WIDTH = 500;
  21. const int HEIGHT = 500;
  22.  
  23. //Farbwerte:
  24. int paintColor = 0;
  25. const int WHITEPAINT = 1;
  26. const int BLACKPAINT = 2;
  27.  
  28. //Variablen fuer Mauskoordinaten in einem Vector2D speichern:
  29. Vector2D mouseXY(0, 0);
  30.  
  31. //Koordinaten fuer Linienzuege: Vector von Vector2D-Punkten mit den jeweiligen Mauskoordinaten:
  32. vector<Vector2D> mouseXYline;
  33.  
  34. //Iterator:
  35. //vector<Vector2D>::iterator it;
  36.  
  37. //wird zum ersten mal gezeichnet?
  38. bool paintfirsttime = true;
  39. //wurde geklickt?
  40.  
  41. void mouse(int button, int state, int x, int y) {
  42.     if (state == GLUT_DOWN) {
  43.         //Punktkoordinaten setzen:
  44.         mouseXY.setX(x);
  45.         mouseXY.setY(HEIGHT - y);
  46.         //Punktkoordinaten zu Vector hinzufuegen:
  47.         mouseXYline.push_back(mouseXY);
  48.         //TESTAUSGABE1
  49.         cout << "OBEN: " << mouseXYline.size() << " I:" << i << endl;
  50.  
  51.         if (button == GLUT_LEFT_BUTTON) {
  52.             paintColor = WHITEPAINT;
  53.             //Linie zeichnen ueber std::Vector
  54.  
  55.         }
  56.         if (button == GLUT_RIGHT_BUTTON) {
  57.             paintColor = BLACKPAINT;
  58.         }
  59.     }
  60.     glutPostRedisplay();
  61. }
  62.  
  63. void drawLine(){
  64.  
  65. }
  66.  
  67. void display() {
  68.     //Punktgroesse & Aliasing:
  69.     glPointSize(3.0);
  70.     glEnable( GL_POINT_SMOOTH);
  71.     //glDisable(GL_POINT_SMOOTH);
  72.  
  73.     //beim ersten Zeichnen den Bildschirm loeschen:
  74.     if (paintfirsttime) {
  75.         glClear ( GL_COLOR_BUFFER_BIT);
  76.         glClearColor(1.0, 0.0, 0.0, 0.0);
  77.         paintfirsttime = false;
  78.     } else {
  79.         if (paintColor == WHITEPAINT) {
  80.             glColor3f(1.0, 1.0, 1.0);
  81.         }
  82.         if (paintColor == BLACKPAINT) {
  83.             glColor3f(0.0, 0.0, 0.0);
  84.         }
  85.         glLineWidth(2.0);
  86.  
  87.  
  88.                 //Anfangs- und Endpunkte der Linie
  89.                 //Zeichne die Linie hier:
  90.  
  91.                 Vector2D begin;
  92.  
  93.                 glBegin( GL_LINES);
  94.  
  95.                 for (int n=1; n<(mouseXYline.size()); n++) {
  96.                 cout << "von (" << mouseXYline.at(n).x() << "," << mouseXYline.at(n).y() << ")" << endl;
  97.                 glVertex2i(mouseXYline.at(n-1).x(), mouseXYline.at(n-1).y());
  98.                 glVertex2i(mouseXYline.at(n).x(), mouseXYline.at(n).y());
  99.                 }
  100.                 glEnd();
  101.                 i++;
  102.         //TESTAUSGABE 2
  103.         cout << "UNTEN: " << mouseXYline.size() << " I:" << i << endl;
  104.     }
  105.     glFlush();
  106. }
  107.  
  108. void init(void) {
  109.     glOrtho(0.0, WIDTH, 0.0, HEIGHT, -1.0, 1.0);
  110. }
  111.  
  112. int main(int argc, char** argv) {
  113.     glutInit(&argc, argv);
  114.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  115.     glutInitWindowSize(WIDTH, HEIGHT);
  116.     glutInitWindowPosition(100, 100);
  117.     glutCreateWindow("Paint");
  118.     init();
  119.     glutMouseFunc(mouse);
  120.     glutDisplayFunc(display);
  121.     glutMainLoop();
  122.  
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement