Rudy Temat założony przez niniejszego użytkownika |
[Allegro] Problemy z math.h » 2009-09-05 11:27:27 Witam. Przepraszam, że ponownie zawracam głowę być może tak banalnym problemem, ale nie umiem go rozwiązać i nigdzie o nim nie pisze. Problem tyczy się biblioteki math w Allegro. Nie chce się ona załadować. Przeglądając inne tematy zauważyłem, że u wszystkich działa, tylko u mnie nie. Kod programu: #include <math.h> #include <allegro.h>
void draw_table( BITMAP * pos, int x, int y, int w, int h, int color, int move, int press ) { int col[ 4 ] = { makecol( max( color - move - move, 0 ) *( floor( press / 1 ) % 2 ) , max( color - move - move, 0 ) *( floor( press / 2 ) % 2 ) , max( color - move - move, 0 ) *( floor( press / 4 ) % 2 ) ) , makecol( max( color - move, 0 ) *( floor( press / 1 ) % 2 ) , max( color - move, 0 ) *( floor( press / 2 ) % 2 ) , max( color - move, 0 ) *( floor( press / 4 ) % 2 ) ) , makecol( color *( floor( press / 1 ) % 2 ) , color *( floor( press / 2 ) % 2 ) , color *( floor( press / 4 ) % 2 ) ) , makecol( min( color + move, 255 ) *( floor( press / 1 ) % 2 ) , min( color + move, 255 ) *( floor( press / 2 ) % 2 ) , min( color + move, 255 ) *( floor( press / 4 ) % 2 ) ) }; rectfill( pos, x + 2, y + 2, x + w - 2, y + h - 2, col[ 2 ] ); hline( pos, x + 1, y + 1, x + w - 1, col[ 3 - 2 *( press > 7 ) ] ); vline( pos, x + 1, y + 2, y + h - 1, col[ 3 - 2 *( press > 7 ) ] ); hline( pos, x + 1, y + h - 2, x + w, col[ 1 + 2 *( press > 7 ) ] ); vline( pos, x + w - 2, y + 1, y + h - 1, col[ 1 + 2 *( press > 7 ) ] ); hline( pos, x, y, x + w, col[ 2 - 2 *( press > 7 ) ] ); vline( pos, x, y + 1, y + h, col[ 2 - 2 *( press > 7 ) ] ); hline( pos, x, y + h - 1, x + w, col[ 0 + 2 *( press > 7 ) ] ); vline( pos, x + w - 1, y, y + h - 1, col[ 0 + 2 *( press > 7 ) ] ); } END_OF_FUNCTION( draw_table );
int main() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 ); clear_to_color( screen, makecol( 192, 192, 192 ) ); draw_table( screen, 100, 100, 200, 150, 192, 64, 7 ); readkey(); allegro_exit(); return( 0 ); } END_OF_MAIN()
Log: Kompilator: Default compiler Building Makefile: "E:\Dev-Cpp\first steps\Makefile.win" Wykonywanie make... make.exe -f "E:\Dev-Cpp\first steps\Makefile.win" all g++.exe -D__DEBUG__ -c "Plik pomocniczy.cpp" -o "Plik pomocniczy.o" -I"E:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"E:/Dev-Cpp/include/c++/3.4.2/backward" -I"E:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"E:/Dev-Cpp/include/c++/3.4.2" -I"E:/Dev-Cpp/include" -DALLEGRO_STATICLINK -pg -g3
g++.exe -D__DEBUG__ -c allegro.cpp -o allegro.o -I"E:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"E:/Dev-Cpp/include/c++/3.4.2/backward" -I"E:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"E:/Dev-Cpp/include/c++/3.4.2" -I"E:/Dev-Cpp/include" -DALLEGRO_STATICLINK -pg -g3
allegro.cpp: In function `void draw_table(BITMAP*, int, int, int, int, int, int, int)': allegro.cpp:6: error: `max' undeclared (first use this function) allegro.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.) allegro.cpp:6: error: invalid operands of types `double' and `int' to binary `operator%'
allegro.cpp:7: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:8: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:9: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:10: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:11: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:12: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:13: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:14: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:15: error: `min' undeclared (first use this function) allegro.cpp:15: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:16: error: invalid operands of types `double' and `int' to binary `operator%' allegro.cpp:17: error: invalid operands of types `double' and `int' to binary `operator%'
make.exe: *** [allegro.o] Error 1
Wykonanie zakończone
kwestią operatorów % zajmę się później, wiem jak to zrobić, chciałbym tylko rozwiązać najpierw problem matha. |
|
DejaVu |
» 2009-09-05 11:38:54 #include <iostream> #include <algorithm> using namespace std;
int main() { cout << max( 3, 5 ) << endl; return 0; } |
|
Rudy Temat założony przez niniejszego użytkownika |
» 2009-09-05 11:52:43 Nie wiem co to miało oznaczać, ale po wprowadzeniu tego kodu nic się nie pokazuje (mimo, iż program jest włączony, dodałem najpierw getch();, potem pętlę nieskończoną). Ale kompilaor nie zatrzymał programu, czyli max działał. Próbowałem także zamienić math.h na algorithm w starym kodzie, błędy dalej się pojawiają. No ale przynajmniej błędy z % zniknęły :) Log wygląda teraz tak: Kompilator: Default compiler Building Makefile: "E:\Dev-Cpp\first steps\Makefile.win" Wykonywanie make... make.exe -f "E:\Dev-Cpp\first steps\Makefile.win" all g++.exe -D__DEBUG__ -c "Plik pomocniczy.cpp" -o "Plik pomocniczy.o" -I"E:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"E:/Dev-Cpp/include/c++/3.4.2/backward" -I"E:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"E:/Dev-Cpp/include/c++/3.4.2" -I"E:/Dev-Cpp/include" -DALLEGRO_STATICLINK -pg -g3
g++.exe -D__DEBUG__ -c allegro.cpp -o allegro.o -I"E:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"E:/Dev-Cpp/include/c++/3.4.2/backward" -I"E:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"E:/Dev-Cpp/include/c++/3.4.2" -I"E:/Dev-Cpp/include" -DALLEGRO_STATICLINK -pg -g3
allegro.cpp: In function `void draw_table(BITMAP*, int, int, int, int, int, int, int)': allegro.cpp:6: error: `max' undeclared (first use this function) allegro.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.) allegro.cpp:6: error: `floor' undeclared (first use this function) allegro.cpp:15: error: `min' undeclared (first use this function)
make.exe: *** [allegro.o] Error 1
Wykonanie zakończone
|
|
Rudy Temat założony przez niniejszego użytkownika |
» 2009-09-05 12:04:52 To też sprawdzałem, i w math, i w algorythm. Nic nie zmienia, dalej są błędy.
EDIT: Spróbowałem jeszcze raz i bardziej przyjrzałem się kompilatorowi. Błędy n/t max i min zniknęły, został floor. |
|
Rudy Temat założony przez niniejszego użytkownika |
» 2009-09-05 13:19:39 floor, min i max działa, ale pojawiły się błędy z "%". Teraz początek wygląda w ten sposób: #include <cmath> #include <algorithm> #include <allegro.h>
using namespace std;
... |
|
DejaVu |
» 2009-09-05 13:29:31 Musisz rzutować na int'a. floor() zwraca zaokrągloną wartość ale nadal jest to liczba zmienno przecinkowa. |
|
Rudy Temat założony przez niniejszego użytkownika |
» 2009-09-05 15:39:47 Dożo roboty, a wcześniej te problemy były rozwiązane... Jeśli jest jakiś sposób, żeby były jednocześnie floor, min, max i operatory bez "static_cast", byłbym wdzięczny. Jendak, aby isc dalej z programem, ustawię zmianę z double'a na inta. Chyba, że jest sposób na modyfikacje floor, żeby zwracała inta? :> |
|
Rudy Temat założony przez niniejszego użytkownika |
» 2009-09-05 16:09:50 Ok, zmieniłem. Dzięki za pomoc, pytanie wyżej nadal aktywne (nawet najkrótsza funkcja będzie dłużej robiona niż brak funkcji) |
|
« 1 » 2 |