OpenGl Projekt

  • Themenstarter Themenstarter GreenThunder
  • Beginndatum Beginndatum
G

GreenThunder

Hallo,

in einem einwöchigen Blockseminar wurde uns eine Einführung in "Computergraphics" (OpenGl in C++) gegeben und als Abschluss sollen wir nun eine kleine Applikation schreiben, die einem Zeichenprogramm ähneln soll.

Dabei tritt für mich nun ein erstes Problem auf. Und zwar hab ich zwei Fenster, ein Menü- und ein Mainwindow.
Im Menü hab ich die Schaltflächen als Rechtecke dargestellt und möchte nun per Maus drauf klicken lassen können. Zum Test ob es geht soll einfach ein neues Rechteck drüber gemalt werden, aber irgendwie klappt es nicht. Kann jemand helfen?

Code:
// Paintbrush

#include <iostream>
#include <GL/glut.h>
#include <math.h>

#pragma comment(lib, "opengl32.lib")  // Link OpenGL32.lib
#pragma comment(lib, "glu32.lib")	  // Link Glu32.lib
#pragma comment(lib, "glut32.lib")    // Link Glut32.lib
#pragma comment(linker, "/entry:\"mainCRTStartup\"" )  // set the entry point to be main()
#pragma comment(linker, "/subsystem:\"Windows\"" )  // set the entry point to be main()
#define DEG_TO_RAD 57.29578;

using namespace std;

void mainwindow();
void menuwindow();
void initmain();
void initmenu();
void mouse(int button, int state, int x, int y);
void menu();
int id;


int main(int argc, char** argv)
{
	cout<<"hello this is opengl"<<endl;

// ########### Mainwindow ############################# 
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(400,400);
	glutInitWindowPosition(350,200);
	glutCreateWindow("Mainwindow");
	glutDisplayFunc(mainwindow);
 	
	initmain();
 
// ########### Menuwindow ############################# 
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(30,400);
	glutInitWindowPosition(200,200);
	glutCreateWindow("Menu");
	glutDisplayFunc(menuwindow);
	//MouseFunction
	glutMouseFunc(mouse);
	initmenu();
 	glutMainLoop();
	return 0;
}

// ########### menu ############################# 
void menu()
{
// Point #######################
	glColor3f(0.0,1.0,0.2);
	glBegin(GL_QUADS);
		glVertex2f(100,475);
		glVertex2f(300,475);
		glVertex2f(300,425);
		glVertex2f(100,425);
	glEnd();

	glPointSize(4.0);
	glColor3f(0.0,0.0,0.0);
	glBegin(GL_POINTS);
		glVertex2f(200,450);
	glEnd();

// Points ########################
	glColor3f(0.0,1.0,0.2);
	glBegin(GL_QUADS);
		glVertex2f(100,400);
		glVertex2f(300,400);
		glVertex2f(300,350);
		glVertex2f(100,350);
	glEnd();

	glPointSize(4.0);
	glColor3f(0.0,0.0,0.0);
	glBegin(GL_POINTS);
		glVertex2f(155,360);
		glVertex2f(200,375);
		glVertex2f(250,380);
	glEnd();
}

// ########### mouse ############################# 
void mouse (int button, int state, int x, int y)
{
// Menupoint #######################
	if (state ==GLUT_DOWN && button==GLUT_LEFT_BUTTON && x >= 300 && x<=400 && y >=425 && y <=475)
		{
		glColor3f(1.0,0.0,0.0);
		glBegin(GL_QUADS);
		glVertex2f(100,475);
		glVertex2f(300,475);
		glVertex2f(300,425);
		glVertex2f(100,425);
		glEnd();
		}	
}

// ########### Mainwindow ############################# 
void mainwindow()
{
	//Clear the window
	glPointSize(4.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glFlush();
}

void initmain()
{
	//Set the background color
	glClearColor(1.0,1.0,1.0,1.0);
    
	//Sets the mode of matrix operation
	glMatrixMode(GL_PROJECTION);
    
	//Initalizes the transformation matrix to Identity matrix
	glLoadIdentity();
    
	//Viewing the image in the screen
	gluOrtho2D(0,500,0,500);
}


// ########### Menuwindow ############################# 

void menuwindow()
{
	//Clear the window
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0.0,0.0,1.0);

	menu();

	//Flush the buffer
	glFlush();
}


void initmenu()
{
	//Set the background color
	glClearColor(1.0,1.0,1.0,1.0);
    
	//Sets the mode of matrix operation
	glMatrixMode(GL_PROJECTION);
    
	//Initalizes the transformation matrix to Identity matrix
	glLoadIdentity();
    
	//Viewing the image in the screen
	gluOrtho2D(0,500,0,500);
}
 
Zurück