Results 1 to 3 of 3

Thread: need help with openGL

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    0


    ผมกำลังเรียน เกี่ยวกับ oepnGl และพบปัญหาในคำสั่ง

    glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, CubeData::cubeIndices);

    มันขึ้นว่า An unhandled exception of type 'System.AccessViolationException' occurred in Cube.exe

    แต่พอไป ลองบนเครื่องอื่น บางเครื่องก็เป็น บ้างก็ไม่เป็น เลยอยากจะหาถามวิธีแก้ ไหมครับ

    โปรแกรม ครับผม
    [code]
    /* ------- SIMPLE ROTATING CUBE PROGRAM

    Interpolated Color Cube created in the origin
    Uses speed up from the glDrawElements

    Left, Middle, Right Mouse will change the axis of the transformation

    Try playing around with the translation, rotation, and scaling
    Try changing the projection


    -------------------------------------- */
    #include <stdlib.h>
    #include <GL/glut.h>


    //namespace used to house cube specific variables
    namespace CubeData
    {

  2. #2
    Senior Member
    Join Date
    Jul 2004
    Location
    Bangkok
    Posts
    187


    Code:
    glEnableClientState(GL_NORMAL_ARRAY);
    คิดว่าเป็นที่บรรทัดนี้ เพราะว่าจากโปรแกรมที่ให้มาไม่ได้กำหนดค่า normal ของจุด ลอง comment ดูน่าจะหาย

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    2


    //flush and swap the buffer to display
    <strike>glFlush();</strike>
    glutSwapBuffers();
    }[/b]
    แนะนำให้ comment คำสั่ง glFlust(); ออกครับ

    ก่อนอื่นขออธิบายก่อนว่า คำสั่ง glFlush(); นั้นใช้ออกคำสั่งให้ OpenGL ทำการโอนถ่ายชุดคำสั่งพร้อมทั้งข้อมูลต่างๆที่คุณได้โปรแกรมไว้
    จาก main memory (แรม) ส่งไปยัง video memory (แรมการ์ดจอ) เพื่อทำการประมวลผลต่อไป
    คือ OpenGL จะไม่ส่งคำสั่งที่คุณเขียนไปทีละบรรทัดหรอกครับ (มันช้า) มันจะกั๊กไว้หลายๆคำสั่ง จนกว่าคุณจะ Flush มันนั่นแหล่ะ มันถึงจะ
    ส่งคำสั่งทั้งหมดนั้นไปให้การ์ดจอประมวลผล

    ต่อมาคือ เนื่องจากโปรแกรมนี้คุณเปิดการใช้งาน Double Buffering โดยสังเกตุได้จาก

    int main(int argc, char **argv)
    {
    glutInit(&argc, argv);

    //Double Buffer and Z Buffer
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);[/b]
    flag GLUT_DOUBLE หมายความว่า คุณต้องการให้โปรแกรมของคุณใช้ 2 buffers ในการแสดงผลบนหน้าจอโดยให้สองบัฟเฟอร์นั้น
    flip (สลับ) ไปมา เพื่อให้ภาพอนิเมชั่นที่ได้มีความลื่นไหลต่อเนื่อง ไม่มีอาการจอกระพริบเป็นช่วงๆ หรืออาำการภาพขาดๆแหว่งๆ

    ข้อแม้ของคำสั่งนี้คือ ถ้าคุณต้องการใช้ Double Buffering แล้ว ในการสั่งให้ OpenGL แสดงผลบนหน้าจอ จะใช้คำสั่ง

    glutSwapBuffers();

    แทนการเรียกคำสั่ง glFlush();

    แต่จากโค๊ดของคุณ ได้ทำการสั่ง glFlush(); ก่อน แล้วจึงสั่ง glutSwapBuffers(); ตาม ซึ่งมันก็ไม่ผิด แต่ในบางครั้งอาจเกิดข้อผิดพลาด
    ในการจัดการกับเมมโมรี่ได้

    ให้แก้ไขโดย ไม่ต้องสั่ง glFlush(); ครับ แค่สั่ง glutSwapBuffers(); ก็พอแล้ว

    ส่วนบรรทัด

    glEnableClientState(GL_NORMAL_ARRAY);[/b]
    เป็นการบอก OpenGL ว่าเราจะมีการใช้งาน Normal vector array ครับ เราจะใช้หรือไม่ใช้ก็ได้ไม่มีผลกระทบอะไร แค่บอกว่าเปิดให้ใช้ได้เท่านั้น

    ปล. glutSwapBuffers(); เป็นคำสั่งที่อยู่ใน Glut library นะครับ ไม่ใช่ของ OpenGL โดยตรง

Similar Threads

  1. อยากได้วิธีเซต OpenGL run บน EditPlus
    By tikmaster in forum C/C++,C#,VC++,MFC,Win32
    Replies: 0
    Last Post: 18-08-2009, 09:47 PM
  2. visual C++ ในชุดคำสั่ง openGL
    By armmetalclub in forum C/C++,C#,VC++,MFC,Win32
    Replies: 1
    Last Post: 11-03-2007, 12:45 AM
  3. OpenGL tutorial
    By asylu3 in forum Game Programming & Computer Graphics
    Replies: 0
    Last Post: 30-10-2004, 01:39 AM
  4. OpenGL trouble shooting
    By asylu3 in forum Game Programming & Computer Graphics
    Replies: 0
    Last Post: 30-10-2004, 01:32 AM
  5. OpenGL คืออะไรค่ะ
    By ar3s in forum Game Programming & Computer Graphics
    Replies: 2
    Last Post: 18-02-2004, 02:47 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •