glDisable(GL_LIGHTING); // luci izklopimo, da svetloba ne vpliva na barvo teksta
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
drawText(0.0f, 0.0f, "test", 1.0f, 1.0f, 1.0f);
glPopMatrix();
restorePerspectiveProjection();
glEnable(GL_LIGHTING);
void drawText(float x, float y, const char* text, float r, float g, float b)
{
// izrise text na ekran
if(!text || !strlen(text)) return;
glColor3f(r, g, b);
glRasterPos2f(2.0f + x, 14.0f + y);
do {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *text);
text++;
} while (*text);
}
GLUT_BITMAP_8_BY_13
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_TIMES_ROMAN_24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18
void mouseButtonEvent(int button, int state, int x, int y)
{
if (state == GLUT_DOWN && button == GLUT_LEFT_BUTTON)
{
if (x >= mojGumb_x && y >= mojGumb_y &&
x <= mojGumb_x + mojGumb_sirina && y <= mojGumb_y + mojGumb_visina)
{
// ... uporabnik je kliknil gumb "mojGumb" ...
}
}
}
int main(int argc, char** argv) {
// za naključna števila
srand((unsigned)time(0));
// generiranje asteroidov
for (int i=0; i<ASTEROIDS; i++) {
asteroids.push_back(new Asteroid());
// cout << asteroids[i]->x << " " << asteroids[i]->y << endl;
}
ship = new Ship();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(10, 10);
glutInitWindowSize(512, 512);
glutCreateWindow("Asteroids");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutKeyboardFunc(tipkovnica);
glutMouseFunc(miska);
glutTimerFunc(1000/FPS, timer, 1);
glClearColor(0, 0, 0, 0);
glutMainLoop();
return 0;
}
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <GL/glut.h>
void Draw2D()
{
}
void Draw()
{
glClear( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Draw2D();
glutSwapBuffers();
}
void MouseButton(int button,int state,int x, int y)
{
if (state == GLUT_DOWN)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
printf("left ");
break;
case GLUT_MIDDLE_BUTTON:
printf("middle ");
break;
case GLUT_RIGHT_BUTTON:
printf("right ");
break;
}
printf("button pressed at (%d,%d)\n",x,y);
}
else
{
switch(button)
{
case GLUT_LEFT_BUTTON:
printf("left ");
break;
case GLUT_MIDDLE_BUTTON:
printf("middle ");
break;
case GLUT_RIGHT_BUTTON:
printf("right ");
break;
}
printf("button released at (%d,%d)\n",x,y);
}
glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(512,512);
glutCreateWindow("Krneki");
glutDisplayFunc(Draw);
glutMouseFunc(MouseButton);
glutMainLoop();
}
glBegin(GL_QUADS)
glVertex2f(x, y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x, y height);
glEnd()
if( x > gumb.x && x < gumb.x + width)
if( y > gumb.y && y < gumb.y + height)
{
// klik na gumb je uspel, in kupili smo 10 krav za na našo kmetijo
// s šalo na stran - tukaj napište kaj se zgodi ob kliku na gumb :)
}
class Gumb(){
Gumb() //constructor
{
x= 0;
y= 0;
width = 128;
height = 128;
}
int x;
int y;
int width;
int height;
char* name;
void Set(int x, int y, int width, int height) //nastavimo vrednosti
{
this->x = x;
this->y = y;
this->width = width;
this->height = height;
}
void Draw() // izris gumba
{
glBegin(GL_QUADS)
glVertex2f(x, y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x, y height);
glEnd()
}
bool IsClicked(int x, int y) // preverimo če je bil pritisnjen
{
if( x > gumb.x && x < gumb.x + width)
if( y > gumb.y && y < gumb.y + height)
{
return true;
}
return false;
}
void SetName(char * name)
{
this->name = name;
}
char* GetName()
{
return name;
}
}
vector<Gumb*> vGumbi;
Gumb *btn = new Gumb();
btn.Set( 128, 128, 100, 20) // gumb bo na poziciji X=128, Y=128, širok bo 100 pikslov, visok pa 20
btn.Name = "gumb_nova_igra"; //ime gumba, da bomo vedli kateri je
vGumbi.pushBack( btn ); // vrzemo gumb v vektor
//po zelji ustvrami vec gumbov
for( int i=0; i< vGumbi.size(); i++ )
{
vGumbi.at(i)->Draw();
}
for( int i=0; i< vGumbi.size(); i++ )
{
if( vGumbi.at()->IsClicked() )
{
if( !strcmp(vGumbi.at()->GetName(), "gumb_nova_igra")
{
//zaženemo igro
break; //skočimo iz zanke ker več kot en gumb ne more biti pritisnjen naenkrat
} else
if( !strcmp(vGumbi..at()->GetName(), "gumb_zajec")
{
//nekaj se zgodi z rjavim zajcem
}
}
}
// strcmp je C-jeva funkcija, ki primerja dva niza med seboj (char*)
// če funkcije vrne 0 pomeni da sta niza enaka
glBegin(GL_QUADS)
glVertex2f(100, 100);
glVertex2f(300, 100);
glVertex2f(300,120);
glVertex2f(100, 120);
glEnd()
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdlib.h>
class Gumb{
int x; // X pozicija gumba
int y; // Y pozicija gumba
int width; // širina
int height; // višina
char* name;
public:
Gumb() //constructor
{
x= 0;
y= 0;
width = 128;
height = 128;
}
void Set(int x, int y, int width, int height) //nastavimo vrednosti
{
this->x = x;
this->y = y;
this->width = width;
this->height = height;
}
void Draw() // izris gumba
{
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x, y+ height);
glEnd();
}
bool IsClicked(int x, int y) // preverimo če je bil pritisnjen
{
if( x > gumb.x && x < gumb.x + width)
if( y > gumb.y && y < gumb.y + height)
{
return true;
}
return false;
}
void SetName(char * name)
{
this->name = name;
}
char* GetName()
{
return name;
}
}
vector<Gumb*> vGumbi;
void Draw()
{
glClear( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
for( int i=0; i< vGumbi.size(); i++ )
{
vGumbi.at(i)->Draw();
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutSwapBuffers();
}
void MouseButton(int button,int state,int x, int y)
{
if (state == GLUT_DOWN)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if( x > x && x < x + width)
if( y > y && y < y + height)
{
printf("nobk ");
// klik na gumb je uspel, in kupili smo 10 krav za na našo kmetijo
// s šalo na stran - tukaj napište kaj se zgodi ob kliku na gumb :)
}
else
printf("nobk ddd");
break;
case GLUT_MIDDLE_BUTTON:
printf("middle ");
break;
case GLUT_RIGHT_BUTTON:
printf("right ");
break;
}
printf("button pressed at (%d,%d)\n",x,y);
}
else
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if( x > x && x < x + width)
if( y > y && y < y + height)
{
printf("nobk ");
// klik na gumb je uspel, in kupili smo 10 krav za na našo kmetijo
// s šalo na stran - tukaj napište kaj se zgodi ob kliku na gumb :)
}
else
printf("nobk ddd");
break;
case GLUT_MIDDLE_BUTTON:
printf("middle ");
break;
case GLUT_RIGHT_BUTTON:
printf("right ");
break;
}
// printf("button released at (%d,%d)\n",x,y);
}
glutPostRedisplay();
}
int main(int argc,char **argv)
{
Gumb *btn = new Gumb();
btn.Set( 128, 128, 100, 20); // gumb bo na poziciji X=128, Y=128, širok bo 100 pikslov, visok pa 20
btn.Name = "gumb_nova_igra"; //ime gumba, da bomo vedli kateri je
vGumbi.pushBack( btn ); // vrzemo gumb v vektor
//po zelji ustvrami vec gumbov
for( int i=0; i< vGumbi.size(); i++ )
{
if( vGumbi.at()->IsClicked() )
{
if( !strcmp(vGumbi.at()->GetName(), "gumb_nova_igra")
{
//zaženemo igro
break; //skočimo iz zanke ker več kot en gumb ne more biti pritisnjen naenkrat
} else
if( !strcmp(vGumbi..at()->GetName(), "gumb_zajec")
{
//nekaj se zgodi z rjavim zajcem
}
}
}
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(512,512);
glutCreateWindow("Krneki");
glutDisplayFunc(Draw);
glutMouseFunc(MouseButton);
glutMainLoop();
}
In member function 'void Gumb::Set(int, int, int, int)':|
40|warning: declaration of 'height' shadows a member of 'this'|
40|warning: declaration of 'width' shadows a member of 'this'|
40|warning: declaration of 'y' shadows a member of 'this'|
|40|warning: declaration of 'x' shadows a member of 'this'|
|In member function 'bool Gumb::IsClicked(int, int)':|
58|warning: declaration of 'y' shadows a member of 'this'|
58|warning: declaration of 'x' shadows a member of 'this'|
|59|error: 'gumb' was not declared in this scope|
||In member function 'void Gumb::SetName(char*)':|
|68|warning: declaration of 'name' shadows a member of 'this'|
77|error: expected initializer before '<' token|
|In function 'void Draw()':|
97|error: 'vGumbi' was not declared in this scope|
|In function 'void MouseButton(int, int, int, int)':|
128|error: 'width' was not declared in this scope|
129|error: 'height' was not declared in this scope|
128|warning: suggest explicit braces to avoid ambiguous 'else'|
154|error: 'width' was not declared in this scope|
155|error: 'height' was not declared in this scope|
154|warning: suggest explicit braces to avoid ambiguous 'else'|
|In function 'int main(int, char**)':|
183|error: request for member 'Set' in 'btn', which is of non-class type 'Gumb*'|
184|error: request for member 'Name' in 'btn', which is of non-class type 'Gumb*'|
185|error: 'vGumbi' was not declared in this scope|
193|error: expected ')' before '{' token|
201|error: expected primary-expression before '}' token|
201|error: expected ';' before '}' token|
549|warning: 'int glutCreateMenu_ATEXIT_HACK(void (*)(int))' defined but not used|
||=== Build finished: 13 errors, 18 warnings ===|
if( !strcmp(vGumbi.at()->GetName(), "gumb_nova_igra")
if( !strcmp(vGumbi..at()->GetName(), "gumb_zajec")
case GLUT_LEFT_BUTTON:
if( x > x && x < x + width)
if( y > y && y < y + height)
128|error: 'width' was not declared in this scope|
129|error: 'height' was not declared in this scope|
#include <vector.h>
using namespace std;
Gumb *btn = new Gumb();
btn.Set( 128, 128, 100, 20); // gumb bo na poziciji X=128, Y=128, širok bo 100 pikslov, visok pa 20
btn.Name = "gumb_nova_igra"; //ime gumba, da bomo vedli kateri je
vGumbi.pushBack( btn ); // vrzemo gumb v vektor
//po zelji ustvrami vec gumbov
request for member 'Set' in 'btn', which is of non-class type 'Gumb*'|
request for member 'Name' in 'btn', which is of non-class type 'Gumb*'|
class std::vector<Gumb*, std::allocator<Gumb*> >' has no member named 'pushBack'|
||=== Build finished: 3 errors, 16 warnings ===|
Gumb *btn = new Gumb();
btn.Set( 128, 128, 100, 20);
btn.Name = "gumb_nova_igra";
vGumbi.pushBack( btn );
Gumb *btn = new Gumb();
btn->Set( 128, 128, 100, 20);
btn->Name = "gumb_nova_igra";
vGumbi.push_back( btn );
Gumb *btn = new Gumb();
btn->Set( 128, 128, 100, 20);
btn->Name = "gumb_nova_igra";
vGumbi.push_back( btn );
btn->SetName ( "gumb_nova_igra");
koscak napisal/-a:Po mojem občutku si malo falil, možn da se motim ampak : tist name ni nič vsaj v gumbku nič, kolikor
- Koda: Izberi vse
btn->SetName ( "gumb_nova_igra");
if( !strcmp(vGumbi.at()->GetName(), "gumb_nova_igra")
{
//zaženemo igro
break;
}
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <GL/glut.h>
#include <vector>
int width=512;
int height=512;
using namespace std;
class Gumb{
int x; // X pozicija gumba
int y; // Y pozicija gumba
int width; // širina
int height; // višina
char* name;
public:
Gumb() //constructor
{
x= 0;
y= 0;
width = 128;
height = 128;
}
void Set(int x, int y, int width, int height) //nastavimo vrednosti
{
this->x = x;
this->y = y;
this->width = width;
this->height = height;
}
void Draw() // izris gumba
{
glBegin(GL_QUADS);
glColor3d(1,0,0);
glVertex2f(x, y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x, y+ height);
glEnd();
}
bool IsClicked(int xx, int yy) // preverimo če je bil pritisnjen
{
if( xx > x && xx < x + width)
if( yy > y && yy < y + height)
{
return true;
}
return false;
}
void SetName(char * name)
{
this->name = name;
}
char* GetName()
{
return name;
}
};
vector<Gumb*> vGumbi;
void Draw()
{
glClear( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT );
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, width, height, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
for( int i=0; i< vGumbi.size(); i++ )
{
vGumbi.at(i)->Draw();
}
glutSwapBuffers();
}
void MouseButton(int button,int state,int x, int y)
{
if (state == GLUT_DOWN)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
// cout<<x<<" "<<y<<" ";
for( int i=0; i< vGumbi.size(); i++ )
{
//preverjanje èe je levi gum pritisnjen
if( vGumbi.at(i)->IsClicked(x,y) )
{
//preverjanje èe je kliknen gum nova igra
if( !strcmp(vGumbi.at(i)->GetName(), "gumb_nova_igra"))
{
}
else if( !strcmp(vGumbi.at(i)->GetName(), "aa"))
{
}
else if( !strcmp(vGumbi.at(i)->GetName(), "exit"))
{
exit(1);
// printf("zapri");
}
break;
}
}
glutPostRedisplay();
}
}
}
int main(int argc,char **argv)
{
Gumb *btn = new Gumb();
btn->Set( 128, 128, 100, 20);
btn->SetName ( "gumb_nova_igra");
vGumbi.push_back( btn );
Gumb *bukn = new Gumb();
bukn->Set( 128, 220, 100, 20);
bukn->SetName ( "exit");
vGumbi.push_back( bukn );
Gumb *bun = new Gumb();
bun->Set( 128, 180, 100, 20);
bun->SetName ( "aa");
vGumbi.push_back( bun );
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(width,height);
glutCreateWindow("Krneki");
glutDisplayFunc(Draw);
glutMouseFunc(MouseButton);
glutMainLoop();
}
Po forumu brska: 0 registriranih uporabnikov in 1 gost