نمایش نتایج 1 تا 8 از 8

نام تاپیک: مشکل در استفاده از یونیت OpenGL در دلفی

  1. #1

    مشکل در استفاده از یونیت OpenGL در دلفی

    سلام:
    من در برنامه ام از یونیت OpenGL به ترتیب زیر استفاده کردم:

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls,
    Forms, Dialogs, OpenGL;

    اما موقع کامپایل و اجرا، بعضی وقتها بدون مشکل عمل می کند اما بعضی وقتها با Error زیر روبرو میشوم؛ که نتونستم دلیلشو پیدا کنم.

    [Fatal Error] OpenGL.pas(5): Program or unit 'OpenGL' recursively uses itself

  2. #2
    بابا شماها که پا مخ برنامه نویسی هستین، پس چرا جواب سوال منو نمی دین ؟
    آخه این سوال من جزو اولین چیزاییه که برنامه نویسه Open GL باهاش روبرو میشه، نه؟
    منتها نمی دونم چرا بعضی وقتا درست جواب میده اما بعضی وقتها توی همون برنامه بدون اینکه هیچ تغییری رخ بده، Error میده.
    لطفا راهنمایی کنین.
    ممنون

  3. #3
    سلام.
    این سوال شما جزو اولین چیزهایی است که در دلفی باید یاد بگیرید و ربطی به OpenGL ندارد.
    recursively uses itself یعنی اینکه :
    A->B->C->D->A

    یونیت A از یونیت B استفاده می کند. یونیت B از یونیت C استفاده می کند. یونیت C از یونیت D استفاده می کند.یونیت D از یونیت A استفاده می کند.
    خوب! برای حل این مشکل ، uses را در قسمت Implementation قرار بده بجای قسمت Interface .

    موفق باشی.

  4. #4
    سلام:

    البته از جواب شما ممنونم
    ببینید من معنی این Error را میفهمم اما نمی دونم چرا این Error رو میده!
    ضمنا این برنامه ای که من نوشتم دقیقا همونیه که در فصل دوم کتاب OpenGL آقای وحید نصیری آورده شده.
    برای همین هم باید ظاهرا بدون عیب باشه، کما اینکه همانطور که قبلا هم گفته بودم، این برنامه بعضی وقتها درست کار می کنه اما دقیقا همون برنامه -بدون اینکه تغییری بکنه- بعضی وقتها Error بالا رو میده.

    راستی من راه حل شما رو هم به کار بردم یعنی Uses را در قسمت Implementation قرار دادم بجای قسمت Interface اما همین Error را داد.
    لطفا اگر راه حلی به ذهنتون میرسه بگید.
    باز هم از راهنماییتون ممنون (;

  5. #5
    الله اکبر
    پس چرا کسی جواب سوال منو نمی ده ):

  6. #6
    کاربر دائمی آواتار MSK
    تاریخ عضویت
    تیر 1383
    محل زندگی
    فعلا تهران - بعدا خدا می‌دونه!
    پست
    331
    اگر در قسمت implementation برنامه قرار دادید و باز هم این error رو داده باید دنبال مشکل در جای دیگه ای بگردید.
    مثلا شاید در یونیتهای دیگر برنامه.
    شاید در نسخه معیوب delphi و ... .
    فکر کنم اگه کدتون رو اینجا بزارید بشه یه کارایی کرد.

  7. #7
    ممنون از راهنماییتون:

    unit OpenGL;
    interface
    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls,
    Forms, Dialogs;
    type
    TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormResize(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    Form1: TForm1;
    hrc: HGLRC; // Permanent Rendering Context
    f_Hdc : LongInt;

    implementation
    uses OpenGL;
    {$R *.DFM}

    procedure InitGL; // All Setup For OpenGL Goes Here
    begin
    // select clearing color
    glClearColor( 0, 0, 0, 0);
    // initialize viewing values
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity;
    glOrtho( 0, 1, 0, 1, -1, 1);
    end;

    procedure DrawGLScene();
    // Here's Where We Do All The Drawing!!!
    //Right after glLoadIdentity and before DrawGLScene:=true
    begin
    // Enable depth testing and clear the color and depth buffers.
    glEnable(GL_DEPTH_TEST);
    // Clear The Screen And The Depth Buffer
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The View
    glOrtho( 0, 1, 0, 1, -1, 1);
    // Set the drawing color to blue.
    glColor3f(1.0, 1.0, 1.0);
    glBegin (GL_POLYGON);
    glVertex3f (0.25, 0.25, 0);
    glVertex3f (0.75, 0.25, 0);
    glVertex3f (0.75, 0.75, 0);
    glVertex3f (0.25, 0.75, 0);
    glEnd;
    // Flush the drawing pipeline.
    glFlush;
    end;

    procedure CleanUp(Handle: HDC); //Properly Kill The Window
    begin
    if hrc<> 0 then //Is There A Rendering Context?
    begin
    //Are We Able To Release Dc and Rc contexts?
    if (not wglMakeCurrent(handle,0)) then
    MessageBox(0,'Release of DC and RC failed.'
    ,' Shutdown Error',MB_OK or MB_ICONERROR);
    //Are We Able To Delete The Rc?
    if (not wglDeleteContext(hRc)) then
    begin
    MessageBox(0,'Release of Rendering Context failed.',
    ' Shutdown Error',MB_OK or MB_ICONERROR);
    hRc:=0; //Set Rc To Null
    end;
    end;
    end;

    procedure SetDCPixelFormat(Handle: HDC;ColorBits,DepthBufferBits:integer);
    var
    pfd: TPixelFormatDescriptor;
    nPixelFormat: Integer;
    begin
    FillChar(pfd, SizeOf(pfd), 0);
    with pfd do begin
    nSize := sizeof(pfd); // Size of this structure
    nVersion := 1; // Version number
    dwFlags := PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW
    Or PFD_TYPE_RGBA; // Flags
    iPixelType:= PFD_TYPE_RGBA; // RGBA pixel values
    cColorBits:= ColorBits; // 24-bit color
    cDepthBits:= DepthBufferBits; // 32-bit depth buffer
    iLayerType:= PFD_MAIN_PLANE; // Layer type
    end;
    nPixelFormat := ChoosePixelFormat(Handle, @pfd);
    //Did We Find A Matching Pixelformat?
    if (nPixelFormat=0) then
    begin
    CleanUp(handle); //Reset The Display
    MessageBox(0,'Cant''t Find A Suitable PixelFormat.'
    ,'Error',MB_OK or MB_ICONEXCLAMATION);
    Halt(1); { Halt right here! }
    end;
    //Are We Able To Set The Pixelformat?
    if (not SetPixelFormat(Handle, nPixelFormat, @pfd)) then
    begin
    CleanUp(handle); //Reset The Display
    MessageBox(0,'Cant''t set PixelFormat.'
    ,'Error',MB_OK or MB_ICONEXCLAMATION);
    Halt(1); { Halt right here! }
    end;
    hrc := wglCreateContext(Handle);
    if (hRc=0) then
    begin
    CleanUp(handle); //Reset The Display
    MessageBox(0,'Cant''t create a GL rendering context.'
    ,'Error',MB_OK or MB_ICONEXCLAMATION);
    Halt(1); { Halt right here! }
    end;
    //Are We Able To Activate The Rendering Context?
    if (not wglMakeCurrent(Handle, hrc)) then
    begin
    CleanUp(handle); //Reset The Display
    MessageBox(0,'Cant''t activate the GL rendering context.'
    ,'Error',MB_OK or MB_ICONEXCLAMATION);
    Halt(1); { Halt right here! }
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    f_Hdc:=GetDC(Handle);
    // Create a rendering context.
    SetDCPixelFormat(f_Hdc,16,16);
    InitGL;
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    // Clean up and terminate.
    CleanUp(f_Hdc);
    end;

    procedure TForm1.FormPaint(Sender: TObject);
    begin
    // Draw the scene.
    wglMakeCurrent(f_Hdc,hrc); //activate the RC
    DrawGLScene;
    end;

    procedure TForm1.FormResize(Sender: TObject);
    begin
    // Redefine the viewing volume and viewport
    //when the window size changes.
    wglMakeCurrent(f_Hdc, hrc);
    // Reset The Current Viewport And Perspective
    // Now, set up the viewing area-select the full client area
    glViewport( 0, 0, Width , Height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity(); // Reset The Projection Matrix
    gluOrtho2D(0, Width, 0, Height);
    DrawGLScene();
    end;
    end.

  8. #8
    باز هم سلام :

    شرمنده، فکر کنم فهمیدم مشکل از کجاست.
    چون اسم یونیت خودم OpenGL هست، و یونیتی به نام OpenGL را هم در برنامه Use می کنم، این مشکل به وجود می یاد. نه !!!؟؟

    از کمک همه دوستان ممنونم.

تاپیک های مشابه

  1. محل دانلود OpenGL V2.1
    نوشته شده توسط توسعه نویس در بخش طراحی و ساخت بازی‌های کامپیوتری
    پاسخ: 10
    آخرین پست: شنبه 19 بهمن 1387, 16:30 عصر
  2. راهنمای opengl
    نوشته شده توسط Alen در بخش برنامه نویسی با زبان C و ++C
    پاسخ: 5
    آخرین پست: جمعه 11 بهمن 1387, 23:00 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •