برنامج OpenGL إلى برنامج OpenGL ES-- تغيير لون المثلثات في قطاع

StackOverflow https://stackoverflow.com/questions/835903

  •  08-07-2019
  •  | 
  •  

سؤال

عند استخدام glBegin () وglEnd () في OpenGL كنت قادرا على تحديد وتغيير اللون بين كل glVertex3f (). كيف يمكنك إعادة هذا السلوك عند استخدام مجموعة قمة الرأس وglDrawArrays (). ومن هنا في OpenGL منتظم.

for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    {
    // Calculate x and y position of the next vertex
    x = 50.0f*sin(angle);
    y = 50.0f*cos(angle);

    // Alternate color between red and green
    if((iPivot %2) == 0)
        glColor3f(0.0f, 1.0f, 0.0f);
    else
        glColor3f(1.0f, 0.0f, 0.0f);

    // Increment pivot to change color next time
    iPivot++;

    // Specify the next vertex for the triangle fan
    glVertex2f(x, y);
    }
هل كانت مفيدة؟

المحلول

ومع glDrawArrays لديك لتمكين glVertexPointer لضبط البيانات قمة الرأس.

في نفس الطريقة يمكنك أيضا تعيين مؤشر العميل ذاكرة للألوان.

وانها تتلخص في هذه المكالمات:

  glEnableClientState (GL_VERTEX_ARRAY);
  glEnableClientState (GL_COLOR_ARRAY); // enables the color-array.

  glVertexPointer (...  // set your vertex-coordinates here..
  glColorPointer (...   // set your color-coorinates here..

  glDrawArrays (... // draw your triangles

وراجع للشغل - يتم التعامل مع الإحداثيات الملمس في نفس الطريق. مجرد استخدام GL_TEXCOORD_ARRAY وglTexCoordPointer لذلك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top