///------------------Buton 2 kod sonu-------------------------------------------------
********************************************************************************
5- Örnek Buton 3:
///------------------------------------------
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <windows.h>
#include <iomanip> /// setpraction (x)
using namespace std;
static char bas[20];
void init();
void display();
int alam=4;/// x lik pencere oranı
int winx=4;/// konum maus hizalama
int winx2=4;
float bred=0.3;
float korx, wxm;
short mk,mk2;
float bred2=0.3;
float korx2, wxm2;
void rakam();
void harfYazak(char *z)
{
unsigned int i;
for (i = 0; i < strlen (z); i++)
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, z[i]);
}
void rakam(){
glColor3f(bred,0,0);
sprintf (bas," %1.0f ",korx*100);
glRasterPos3f (0.20, 0.42,0);
harfYazak (bas);
glColor3f(bred2,0,0);
sprintf (bas," %1.0f ",korx2*100);
glRasterPos3f (0.20, -0.55,0);
harfYazak (bas);
}
void buton(){
glPushMatrix();
glColor3f(bred, 0.0, 0.0);
glTranslatef(-0.98,0.5,0);
glPointSize(10.0);
glBegin(GL_POINTS);
glVertex2f(korx,0.0);
glEnd();
glPopMatrix();
}
void lines(){
glColor3f(bred, 0.0, 0.0);
glPushMatrix();
glTranslatef(-0.98,0.0,0);
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex2f(0,0.5);
glVertex2f(korx,0.5); glColor3f(0.3,0.3,0.3);
glEnd();
glPopMatrix();
glutPostRedisplay();
}
///-----------------------------
void buton2(){
glPushMatrix();
glColor3f(bred2, 0.0, 0.0);
glTranslatef(-0.98,-0.5,0);
glPointSize(10.0);
glBegin(GL_POINTS);
glVertex2f(korx2,0.0);
glEnd();
glPopMatrix();
}
void lines2(){
glColor3f(bred2, 0.0, 0.0);
glPushMatrix();
glTranslatef(-0.98,0.0,0);
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex2f(0,-0.5);
glVertex2f(korx2,-0.5); glColor3f(0.3,0.3,0.3);
glEnd();
glPopMatrix();
glutPostRedisplay();
}
void fon(){
glPushMatrix();
glTranslatef(0,0.0,0);
glColor3f(0.5,0.5,0.5);
glBegin(GL_QUADS); /// arka fon
glVertex2f(-1.0,-1.0);
glVertex2f( 1.0,-1.0);
glVertex2f( 1.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();
glColor3f(0.8,0.8,0.8);
glBegin(GL_QUADS); /// buton 1
glVertex2f(-0.98, 0.95);
glVertex2f( 0.98, 0.95);
glVertex2f( 0.98, 0.05);
glVertex2f(-0.98, 0.05);
glEnd();
glBegin(GL_QUADS); /// buton 2
glVertex2f(-0.98,- 0.95);
glVertex2f( 0.98, -0.95);
glVertex2f( 0.98, -0.05);
glVertex2f(-0.98, -0.05);
glEnd();
glPopMatrix();
glPushMatrix(); /// orta line
glLineWidth(1.0);
glColor3f(0.65,0.65,0.65);
glBegin(GL_LINES);
glVertex2f(-0.98,0.0);
glVertex2f( 0.98,0.0);
glEnd();
glPopMatrix();
}
///------------------------------
void init(){
glClearColor(1.0,1.0,1.0,1.0);
gluOrtho2D(0.0, 600.0, 0.0, 600.0);
}
void display(){
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
fon();
lines();
buton();
lines2();
buton2();
rakam();
glutSwapBuffers();
}
void mausKullan(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON) {
if (state == GLUT_DOWN) { // left mouse button pressed
if(y<=74&&x<=200)
{bred=1;}
if(y>=76&&x<=200)
{bred2=1; }
} else {bred=0.3;bred2=0.3; }
glutPostRedisplay();
}}
void pasive_mouseTut(int x,int y){
if(y<=74&&x<=210)
bred=0.65; else bred=0.3;
if(y>=76&&x<=210){ bred2=0.65;} else bred2=0.3;
/// glutPostRedisplay();
}
void mouseHIZ(int nx, int ny)
{
if(ny<=74)mk=1;
if(mk==1) {
if(mk==1)mk=0;else mk=1;
wxm =(winx- nx)*(-0.02);
korx=wxm/alam;
if(korx<=0.0)korx=0.0;
if(korx>=1.0)korx=1.0;}
if(ny>=76)mk2=1;
if(mk2==1){
if(mk2==1)mk2=0;else mk2=1;
wxm2 =(winx2- nx)*(-0.02);
korx2=wxm2/alam;
if(korx2<=0.0)korx2=0.0;
if(korx2>=1.0)korx2=1.0; }
///cout<<"Penx:"<<nx<<" korx:"<<korx<<" k2:"<<korx2<<endl;
glutPostRedisplay();
}
void ess (unsigned char k, int x, int y)
{
if(k==27) exit(0);
}
int main(int argc, char* argv[]){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(400,150);/// y attırılabilir
glutInitWindowPosition(300,300);
glutCreateWindow("OpenGL Program");
init();
glutDisplayFunc(display);
glutMouseFunc(mausKullan);
glutPassiveMotionFunc(pasive_mouseTut);
glutMotionFunc(mouseHIZ);
glutKeyboardFunc(ess);
glutMainLoop();
return 0;
}
///------------------------------------------------------------------------------------------------