Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * gettin_started.cpp
- *
- * Created on: 03.11.2010
- * Author: s_inchen
- */
- #include <stdlib.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <vector>
- #include "Vector2D.h"
- #include <iostream>
- using namespace std;
- //Laufvariable i:
- int i = 0;
- //Fenstergroesse:
- const int WIDTH = 500;
- const int HEIGHT = 500;
- //Farbwerte:
- int paintColor = 0;
- const int WHITEPAINT = 1;
- const int BLACKPAINT = 2;
- //Variablen fuer Mauskoordinaten in einem Vector2D speichern:
- Vector2D mouseXY(0, 0);
- //Koordinaten fuer Linienzuege: Vector von Vector2D-Punkten mit den jeweiligen Mauskoordinaten:
- vector<Vector2D> mouseXYline;
- //Iterator:
- //vector<Vector2D>::iterator it;
- //wird zum ersten mal gezeichnet?
- bool paintfirsttime = true;
- //wurde geklickt?
- void mouse(int button, int state, int x, int y) {
- if (state == GLUT_DOWN) {
- //Punktkoordinaten setzen:
- mouseXY.setX(x);
- mouseXY.setY(HEIGHT - y);
- //Punktkoordinaten zu Vector hinzufuegen:
- mouseXYline.push_back(mouseXY);
- //TESTAUSGABE1
- cout << "OBEN: " << mouseXYline.size() << " I:" << i << endl;
- if (button == GLUT_LEFT_BUTTON) {
- paintColor = WHITEPAINT;
- //Linie zeichnen ueber std::Vector
- }
- if (button == GLUT_RIGHT_BUTTON) {
- paintColor = BLACKPAINT;
- }
- }
- glutPostRedisplay();
- }
- void drawLine(){
- }
- void display() {
- //Punktgroesse & Aliasing:
- glPointSize(3.0);
- glEnable( GL_POINT_SMOOTH);
- //glDisable(GL_POINT_SMOOTH);
- //beim ersten Zeichnen den Bildschirm loeschen:
- if (paintfirsttime) {
- glClear ( GL_COLOR_BUFFER_BIT);
- glClearColor(1.0, 0.0, 0.0, 0.0);
- paintfirsttime = false;
- } else {
- if (paintColor == WHITEPAINT) {
- glColor3f(1.0, 1.0, 1.0);
- }
- if (paintColor == BLACKPAINT) {
- glColor3f(0.0, 0.0, 0.0);
- }
- glLineWidth(2.0);
- //Anfangs- und Endpunkte der Linie
- //Zeichne die Linie hier:
- Vector2D begin;
- glBegin( GL_LINES);
- for (int n=1; n<(mouseXYline.size()); n++) {
- cout << "von (" << mouseXYline.at(n).x() << "," << mouseXYline.at(n).y() << ")" << endl;
- glVertex2i(mouseXYline.at(n-1).x(), mouseXYline.at(n-1).y());
- glVertex2i(mouseXYline.at(n).x(), mouseXYline.at(n).y());
- }
- glEnd();
- i++;
- //TESTAUSGABE 2
- cout << "UNTEN: " << mouseXYline.size() << " I:" << i << endl;
- }
- glFlush();
- }
- void init(void) {
- glOrtho(0.0, WIDTH, 0.0, HEIGHT, -1.0, 1.0);
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(WIDTH, HEIGHT);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Paint");
- init();
- glutMouseFunc(mouse);
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement