dir.by  
Поиск >>

Компьютер, программы
→
Mobile Development with C++ (iOS, Android, Windows Phone)
 Рисование линий в приложении Android C++ используя OpenGL на компьютере (Windows) 
посмотрели 7078 раз
обновлено: 7 July 2023
Шаг 1. Создаем новое C++ приложение для Android
Шаг 2. Поменяем код в файле main.cpp
  Добавим код в конце функции engine_init_display в файле main.cpp
static int engine_init_display(struct engine* engine) {
     ...

     // enable draw lines and colors
     glEnableClientState(GL_VERTEX_ARRAY);// glEnableClientState(GL_VERTEX_ARRAY) allow to use glVertexPointer
     glEnableClientState(GL_COLOR_ARRAY); // glEnableClientState(GL_COLOR_ARRAY) allow to use glColorPointer

     return 0;
}
  Полностью перепишем содержимое функции engine_draw_frame в файле main.cpp
static void engine_draw_frame(struct engine* engine) {
     if (engine->display == NULL) {
          // No display.
          return;
     }

     // set color (white)
     glClearColor(255, 255 ,255, 0);

     // fill device with color
     glClear(GL_COLOR_BUFFER_BIT);

     // set line points and line colors
     static GLfloat colors[] = {
                              1.0f, 0.0f, 0.0f, 1.0f, // red color
                              0.0f, 1.0f, 0.0f, 1.0f, // green color
                              0.0f, 0.0f, 1.0f, 1.0f // blue color
     };
     static GLfloat points[] = {
                         0, 0, 0,
                         0.9, 0.9, 0,
                         0.9, 0, 0
     };

     // draw line points and line color
     glLineWidth(10);
     glVertexPointer(3 /*columns count in variable points*/, GL_FLOAT, 0, points);
     glColorPointer(4 /*columns count in variable colors*/ , GL_FLOAT, 0, colors);
     glDrawArrays(GL_LINE_STRIP, 0 /*first index to draw*/, 3 /*count of points to draw*/);

     // switch gl buffers
     eglSwapBuffers(engine->display, engine->surface);
}
Шаг 3. Запуск приложения
• Компилирем приложение: Menu → Build → Build Solution (F7)
нет ошибок

• Запускаем приложение: Menu → Debug → Start Without Debugging (Ctrl + F5)
Работает!
На заметку
Экран в OpenGL по оси X от -1 до 1
Экран в OpenGL по оси Y от -1 до 1
Скачать пример (весь исходный код)
Android1.zip ...
размер: 18 mb
 
← Previous topic
How to Create an Android Virtual Device in Visual Studio 2019
 
Next topic →
Sites to learn C++ Mobile Development
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
• What is C++ Mobile Development?
• Download and install Microsoft Visual Studio 2019 to write applications for Android, iOS in C++
Writing a C++ application on a computer (Windows) in Android emulator mode
• Creating a new C++ application on a computer (Windows) in Android emulator mode
• Running and debugging a C++ application on a computer (Windows) in Android emulator mode
• Running and debugging a C++ application via USB cable on a Samsung Android phone
Android (install)
• Install the Android platform (SDK 7 API 25, SDK 8 API 26) in Visual Studio 2019
• How to Create an Android Virtual Device in Visual Studio 2019
C++ OpenGL functionality
• Drawing lines in an Android C++ app using OpenGL on a computer (Windows)
WWW Sites to Learn C++ Mobile Development
• Sites to learn C++ Mobile Development

  Ваши вопросы присылайте по почте: info@dir.by