Форум программистов, компьютерный форум, киберфорум
OpenGL
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.53/30: Рейтинг темы: голосов - 30, средняя оценка - 4.53
быдлокодер
1724 / 911 / 106
Регистрация: 04.06.2008
Сообщений: 5,679
1

Анимация в OpenGL, а где собсно, анимация?

22.02.2012, 15:12. Показов 6230. Ответов 5
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
это?
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Bounce.cpp
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [EMAIL="rwright@starstonesoftware.com"]rwright@starstonesoftware.com[/EMAIL]
 
//#include "../../shared/gltools.h"    // OpenGL toolkit
#define _STDCALL_SUPPORTED
#include <GL\glut.h>
 
 
// Initial square position and size
GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat rsize = 25;
 
// Step size in x and y directions
// (number of pixels to move each time)
GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;
 
// Keep track of windows changing width and height
GLfloat windowWidth;
GLfloat windowHeight;
 
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);
 
       // Set current drawing color to red
    //           R     G       B
    glColor3f(1.0f, 0.0f, 0.0f);
 
    // Draw a filled rectangle with current color
    glRectf(x, y, x + rsize, y - rsize);
 
    // Flush drawing commands and swap
    glutSwapBuffers();
    }
 
///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
    {
    // Reverse direction when you reach left or right edge
    if(x > windowWidth-rsize || x < -windowWidth)
        xstep = -xstep;
 
    // Reverse direction when you reach top or bottom edge
    if(y > windowHeight || y < -windowHeight + rsize)
        ystep = -ystep;
 
    // Actually move the square
    x += xstep;
    y += ystep;
 
    // Check bounds. This is in case the window is made
    // smaller while the rectangle is bouncing and the 
    // rectangle suddenly finds itself outside the new
    // clipping volume
    if(x > (windowWidth-rsize + xstep))
        x = windowWidth-rsize-1;
    else if(x < -(windowWidth + xstep))
        x = -windowWidth -1;
 
    if(y > (windowHeight + ystep))
        y = windowHeight-1; 
    else if(y < -(windowHeight - rsize + ystep))
        y = -windowHeight + rsize - 1;
 
 
 
     // Redraw the scene with new coordinates
    glutPostRedisplay();
    glutTimerFunc(33,TimerFunction, 1);
    }
 
 
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
    {
    // Set clear color to blue
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }
 
 
///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(int w, int h)
    {
    GLfloat aspectRatio;
 
    // Prevent a divide by zero
    if(h == 0)
        h = 1;
        
    // Set Viewport to window dimensions
    glViewport(0, 0, w, h);
 
    // Reset coordinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
 
    // Establish clipping volume (left, right, bottom, top, near, far)
    aspectRatio = (GLfloat)w / (GLfloat)h;
    if (w <= h) 
        {
        windowWidth = 100;
        windowHeight = 100 / aspectRatio;
        glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
        }
    else 
        {
        windowWidth = 100 * aspectRatio;
        windowHeight = 100;
        glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
        }
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }
 
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(800,600);
    glutCreateWindow("Bounce");
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);
    glutTimerFunc(33, TimerFunction, 1);
 
    SetupRC();
 
    glutMainLoop();
        
    return 0;
    }


...Код взят из книги "Open, супер книга", там красный квадратик бегает по синему полю. Он у меня побегает- побегает секунд 5 и останавливается. Так, а ещё я рисовал на основе имеющегося кода два квадратика (ещё хуже получается), тоже побегают-побегают и останавливаются. Чтобы убыстрить как-то их джвижение, о том нет и речи, только замедлять, увеличивая первый параметр

glutTimerFunc(33,TimerFunction, 1);

Я ничё не понимаю если уж один несчастный квадратик еле-еле прорисовывается... А как же игры? Или OpenGL толкьо для статики? Спасибо, кто откликнется!
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
22.02.2012, 15:12
Ответы с готовыми решениями:

Qt + OpenGL. Анимация
Пытаюсь сделать анимацию, но не понимаю что да как... Объясните пожалуйста. *.h class GLWidget...

анимация в openGL на С++
У кого работает на пишите пожалуйста? #include &lt;GL/freeglut.h&gt; Предоприделим глобальными...

OpenGl анимация
Всем привет. Нужно написать анимацию для вывода спрайта. Анимация заключается в замене...

Анимация куба OpenGL (C++)
У меня нарисована по граням игральная кость. Используется glEnable(GL_DEPTH_TEST) для глубины и...

5
247 / 52 / 1
Регистрация: 21.05.2011
Сообщений: 297
22.02.2012, 17:14 2
У меня все прекрасно "плавает" , значит в коде все впорядке , у вас в чем-то проблема

Добавлено через 44 секунды
П.С. я использую freeglut
0
быдлокодер
1724 / 911 / 106
Регистрация: 04.06.2008
Сообщений: 5,679
22.02.2012, 17:36  [ТС] 3
А в чём может быть проблема? Комп современный, процессор мощный. Так и у меня тоже плавает до поры лдо времени, а потом останавливается. А вот два квадрата
два бегающих квадрата
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Bounce.cpp
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [EMAIL="rwright@starstonesoftware.com"]rwright@starstonesoftware.com[/EMAIL]
 
//#include "../../shared/gltools.h"    // OpenGL toolkit
#define _STDCALL_SUPPORTED
#include <GL\glut.h>
 
 
// Initial square position and size
GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat x_1 = 0.0f;
GLfloat y_1 = 0.0f;
GLfloat rsize = 70;
 
// Step size in x and y directions
// (number of pixels to move each time)
//GLfloat xstep = 1.0f;
//GLfloat ystep = 1.0f;
GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;
GLfloat xstep_1 = 1.0f;
GLfloat ystep_1 = 1.0f;
 
// Keep track of windows changing width and height
GLfloat windowWidth;
GLfloat windowHeight;
 
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);
 
       // Set current drawing color to red
    //           R     G       B
    glColor3f(1.0f, 0.0f, 0.0f);
 
    // Draw a filled rectangle with current color
    glRectf(x, y, x + rsize, y - rsize);
 
    glColor3f(1.0f, 1.0f, 0.0f);
    glRectf(x_1, y_1, x_1 + rsize, y_1 - rsize);
 
 
    // Flush drawing commands and swap
    glutSwapBuffers();
    }
 
///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
    {
    // Reverse direction when you reach left or right edge
    if(x > windowWidth-rsize || x < -windowWidth)
        xstep = -xstep;
    if(x_1 > windowWidth-rsize || x_1 < -windowWidth)
        xstep_1 = -xstep_1;
 
    // Reverse direction when you reach top or bottom edge
    if(y > windowHeight || y < -windowHeight + rsize)
        ystep = -ystep;
    if(y_1 > windowHeight || y_1 < -windowHeight + rsize)
        ystep_1 = -ystep_1;
 
    // Actually move the square
    x += xstep;
    y += ystep;
    x_1 -= xstep_1;
    y_1 -= ystep_1;
 
    // Check bounds. This is in case the window is made
    // smaller while the rectangle is bouncing and the 
    // rectangle suddenly finds itself outside the new
    // clipping volume
    if(x > (windowWidth-rsize + xstep))
        x = windowWidth-rsize-1;
    else if(x < -(windowWidth + xstep))
        x = -windowWidth -1;
 
    if(y > (windowHeight + ystep))
        y = windowHeight-1; 
    else if(y < -(windowHeight - rsize + ystep))
        y = -windowHeight + rsize - 1;
 
 
 
     // Redraw the scene with new coordinates
    glutPostRedisplay();
    glutTimerFunc(33,TimerFunction, 1);
    }
 
 
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
    {
    // Set clear color to blue
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }
 
 
///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(int w, int h)
    {
    GLfloat aspectRatio;
 
    // Prevent a divide by zero
    if(h == 0)
        h = 1;
        
    // Set Viewport to window dimensions
    glViewport(0, 0, w, h);
 
    // Reset coordinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
 
    // Establish clipping volume (left, right, bottom, top, near, far)
    aspectRatio = (GLfloat)w / (GLfloat)h;
    if (w <= h) 
        {
        windowWidth = 100;
        windowHeight = 100 / aspectRatio;
        glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
        }
    else 
        {
        windowWidth = 100 * aspectRatio;
        windowHeight = 100;
        glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
        }
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }
 
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(800,600);
    glutCreateWindow("Bounce");
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);
    glutTimerFunc(33, TimerFunction, 1);
 
    SetupRC();
 
    glutMainLoop();
        
    return 0;
    }

Эти вообще от стены до стены не успевают долететь, как останавливаются
0
247 / 52 / 1
Регистрация: 21.05.2011
Сообщений: 297
22.02.2012, 17:40 4
Может какой-то глюк в библиотеке , хз , может драйвер коряво стоит , я впервые такое слышу. Попробуйте на библиотеке freeglut такое сделать, может забегает , счас ссылку кину.

Добавлено через 45 секунд
на те http://www.transmissionzero.co... lut-devel/
1
быдлокодер
1724 / 911 / 106
Регистрация: 04.06.2008
Сообщений: 5,679
22.02.2012, 22:00  [ТС] 5
Nequti, никогда с видео проблем не было, правда я первый раз работю с OpenGL, но я имею ввиду фильмы там всякие. Блин, я программу сделал, окна перемещаются туда-сюда, хоть 20, хоть 30 штук, только притормаживать начинают. Просьба, скинь мне экзешщники которые у тебя получились.

Добавлено через 3 часа 55 минут
Nequti, спасибо, реально помог, freeglut выручила, тьфу-тьфу-тьфу, щас у меня по экрану три квадрата бегают только шуба заворачивается

вот
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Bounce.cpp
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [email]rwright@starstonesoftware.com[/email]
 
//#include "../../shared/gltools.h"    // OpenGL toolkit
#define _STDCALL_SUPPORTED
#include <GL\glut.h>
 
 
// Initial square position and size
GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat x_1 = 0.0f;
GLfloat y_1 = 0.0f;
GLfloat x_2 = 0.0f;
GLfloat y_2 = 0.0f;
GLfloat rsize = 70;
 
// Step size in x and y directions
// (number of pixels to move each time)
//GLfloat xstep = 1.0f;
//GLfloat ystep = 1.0f;
GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;
GLfloat xstep_1 = 1.0f;
GLfloat ystep_1 = 1.0f;
GLfloat xstep_2 = 1.0f;
GLfloat ystep_2 = 1.0f;
 
// Keep track of windows changing width and height
GLfloat windowWidth;
GLfloat windowHeight;
 
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);
 
       // Set current drawing color to red
    //           R     G       B
    glColor3f(1.0f, 0.0f, 0.0f);
 
    // Draw a filled rectangle with current color
    glRectf(x, y, x + rsize, y - rsize);
 
    glColor3f(1.0f, 1.0f, 0.0f);
    glRectf(x_1, y_1, x_1 + rsize, y_1 - rsize);
 
 
    glColor3f(0.0f, 1.0f, 0.0f);
    glRectf(x_2, y_2, x_2 + rsize, y_2 - rsize);
 
    // Flush drawing commands and swap
    glutSwapBuffers();
    }
 
///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
    {
    // Reverse direction when you reach left or right edge
    if(x > windowWidth-rsize || x < -windowWidth)
        xstep = -xstep;
    if(x_1 > windowWidth-rsize || x_1 < -windowWidth)
        xstep_1 = -xstep_1;
    if(x_2 > windowWidth-rsize || x_2 < -windowWidth)
        xstep_2 = -xstep_2;
 
    // Reverse direction when you reach top or bottom edge
    if(y > windowHeight || y < -windowHeight + rsize)
        ystep = -ystep;
    if(y_1 > windowHeight || y_1 < -windowHeight + rsize)
        ystep_1 = -ystep_1;
    if(y_2 > windowHeight || y_2 < -windowHeight + rsize)
        ystep_2 = -ystep_2;
 
    // Actually move the square
    x += xstep;
    y += ystep;
    x_1 -= xstep_1;
    y_1 -= ystep_1;
    x_2 += xstep_2;
    y_2 -= ystep_2;
 
    // Check bounds. This is in case the window is made
    // smaller while the rectangle is bouncing and the 
    // rectangle suddenly finds itself outside the new
    // clipping volume
    if(x > (windowWidth-rsize + xstep))
        x = windowWidth-rsize-1;
    else if(x < -(windowWidth + xstep))
        x = -windowWidth -1;
 
    if(y > (windowHeight + ystep))
        y = windowHeight-1; 
    else if(y < -(windowHeight - rsize + ystep))
        y = -windowHeight + rsize - 1;
 
 
 
     // Redraw the scene with new coordinates
    glutPostRedisplay();
    glutTimerFunc(20,TimerFunction, 1);
    }
 
 
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
    {
    // Set clear color to blue
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }
 
 
///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(int w, int h)
    {
    GLfloat aspectRatio;
 
    // Prevent a divide by zero
    if(h == 0)
        h = 1;
        
    // Set Viewport to window dimensions
    glViewport(0, 0, w, h);
 
    // Reset coordinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
 
    // Establish clipping volume (left, right, bottom, top, near, far)
    aspectRatio = (GLfloat)w / (GLfloat)h;
    if (w <= h) 
        {
        windowWidth = 100;
        windowHeight = 100 / aspectRatio;
        glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
        }
    else 
        {
        windowWidth = 100 * aspectRatio;
        windowHeight = 100;
        glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
        }
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }
 
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(800,600);
    glutCreateWindow("Bounce");
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);
    glutTimerFunc(33, TimerFunction, 1);
 
    SetupRC();
 
    glutMainLoop();
        
    return 0;
    }

Моя сборка glut была кривой, по скачке там был файл libglut32.lib, я его САМ переделывыал в libglut32.a (утилита reimp) и работал с ним.
+++++++++++++++++++++++++++++++++++++++
Всё ж таки интересно, что такого могло быт в моей самодельной сборке glut, что проекты работали, НО КРИВО, ладно бы исключение какое выкидывалось... А впрочем, чёрт с ним со всем придёт время- буду разбираться. Спасибо!
0
Nequti
23.02.2012, 04:41     Анимация в OpenGL, а где собсно, анимация?
  #6

Не по теме:

Ну значит ваша самоделькинская работа и что-то испортила, скорее всего.

0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
23.02.2012, 04:41

opengl анимация снег
не могу создать анимацию снега, помогите пожалуйста! вот снеговик, его нужно сделать прозрачным,...

opengl - анимация сферы
Пожалуйста, помогите. хотя бы советом)). задача состоит в том, чтобы прога рисовала трехмерный...

Спрайтовая анимация в OpenGL
Здравствуйте. Собственно, вопрос таков: как реализовать спрайтовую (покадровую) анимацию персонажа...

Анимация сортировки массива на OpenGL
Задали курсовую анимация сортировки массива на OpenGL, элементы массива представляются...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
6
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru