Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 14:26

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Di Nov 15, 2005 20:21 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
Hallo,

ich möchte mir nurbs-Flächen anzeigen. Die gl- und glu-Funktionen werden ohne Fehler aufgerufen aber man sieht nichts auf dem Bildschirm. Ich benutze die dglOpenGL(1.5, Version 1.9, 19.04.2005), die ich mir hier herunter geladen habe. Folgendes mache ich:

Code:
  1.  
  2. unit NurbTest;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs, dglOpenGL;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     procedure FormResize(Sender: TObject);
  13.     procedure FormPaint(Sender: TObject);
  14.     procedure FormDestroy(Sender: TObject);
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.   { Private declarations }
  24.   h_DC   : HDC;                      // Global device context
  25.   h_RC   : HGLRC;                    // OpenGL rendering context
  26.   // Nurb variables
  27.   PNurb : PGLUnurbs;
  28.   numPoints : Integer = 4;
  29.   Knots : Array[0..7] of glFloat = (0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0);
  30.   ControlPoints : Array[0..3, 0..3, 0..2] of glFloat = (
  31.   ((-7.5, -8.0, 0.0), (-9.8, -2.7, 0.0 ), (-11.0, 4.0, 0.0 ), (-9.5,  9.5, 0.0)),
  32.   ((-5.0, -8.3, 7.5), (-5.3, -7.2, 10.0), (-6.0, -1.8, 10.0), (-7.0,  7.8, 5.0)),
  33.   (( 5.0, -8.3, 7.5), ( 5.3, -7.2, 10.0), ( 6.0, -1.8, 10.0), ( 7.0,  7.8, 5.0)),
  34.   (( 7.5, -8.0, 0.0), ( 9.8, -2.7, 0.0 ), ( 11.0, 4.0, 0.0 ), ( 9.5,  9.5, 0.0)));
  35.  
  36. implementation
  37.  
  38. {$R *.dfm}
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. var
  42.   pfd: TPixelFormatDescriptor;
  43.   FormatIndex: integer;
  44.   PixelFormat : GLuint;         // Settings for the OpenGL rendering
  45. begin
  46.   inherited Loaded;
  47.   if (Owner<>nil) then
  48.   fillchar(pfd,SizeOf(pfd),0);
  49.   with pfd do
  50.   begin
  51.     nSize           := SizeOf(TPIXELFORMATDESCRIPTOR); // Size Of This Pixel Format Descriptor
  52.     nVersion        := 1;                    // The version of this data structure
  53.     dwFlags         := PFD_DRAW_TO_WINDOW    // Buffer supports drawing to window
  54.                        or PFD_SUPPORT_OPENGL // Buffer supports OpenGL drawing
  55.                        or PFD_DOUBLEBUFFER;  // Supports double buffering
  56.     iPixelType      := PFD_TYPE_RGBA;        // RGBA color format
  57.     cColorBits      := 32;                   // OpenGL color depth
  58.     cRedBits        := 0;                    // Number of red bitplanes
  59.     cRedShift       := 0;                    // Shift count for red bitplanes
  60.     cGreenBits      := 0;                    // Number of green bitplanes
  61.     cGreenShift     := 0;                    // Shift count for green bitplanes
  62.     cBlueBits       := 0;                    // Number of blue bitplanes
  63.     cBlueShift      := 0;                    // Shift count for blue bitplanes
  64.     cAlphaBits      := 0;                    // Not supported
  65.     cAlphaShift     := 0;                    // Not supported
  66.     cAccumBits      := 0;                    // No accumulation buffer
  67.     cAccumRedBits   := 0;                    // Number of red bits in a-buffer
  68.     cAccumGreenBits := 0;                    // Number of green bits in a-buffer
  69.     cAccumBlueBits  := 0;                    // Number of blue bits in a-buffer
  70.     cAccumAlphaBits := 0;                    // Number of alpha bits in a-buffer
  71.     cDepthBits      := 16;                   // Specifies the depth of the depth buffer
  72.     cStencilBits    := 0;                    // Turn off stencil buffer
  73.     cAuxBuffers     := 0;                    // Not supported
  74.     iLayerType      := PFD_MAIN_PLANE;       // Ignored
  75.     bReserved       := 0;                    // Number of overlay and underlay planes
  76.     dwLayerMask     := 0;                    // Ignored
  77.     dwVisibleMask   := 0;                    // Transparent color of underlay plane
  78.     dwDamageMask    := 0;                     // Ignored
  79.   end;
  80.  
  81.   InitOpenGL;
  82.  
  83.   // Try to get a device context
  84.   h_DC := GetDC(Handle);
  85.   if (h_DC = 0) then
  86.   begin
  87.     MessageBox(0, 'Unable to get a device context!', 'Error', MB_OK or MB_ICONERROR);
  88.     Exit;
  89.   end;
  90.   // Attempts to find the pixel format supported by a device context that is the best match to a given pixel format specification.
  91.   PixelFormat := ChoosePixelFormat(h_DC, @pfd);
  92.   if (PixelFormat = 0) then
  93.   begin
  94.     MessageBox(0, 'Unable to find a suitable pixel format', 'Error', MB_OK or MB_ICONERROR);
  95.     Exit;
  96.   end;
  97.  
  98.   // Sets the specified device context's pixel format to the format specified by the PixelFormat.
  99.   if (not SetPixelFormat(h_DC, PixelFormat, @pfd)) then
  100.   begin
  101.     MessageBox(0, 'Unable to set the pixel format', 'Error', MB_OK or MB_ICONERROR);
  102.     Exit;
  103.   end;
  104.  
  105.   // Create a OpenGL rendering context
  106.   h_RC := wglCreateContext(h_DC);
  107.   if (h_RC = 0) then
  108.   begin
  109.     MessageBox(0, 'Unable to create an OpenGL rendering context', 'Error', MB_OK or MB_ICONERROR);
  110.     Exit;
  111.   end;
  112.  
  113.   // Makes the specified OpenGL rendering context the calling thread's current rendering context
  114.   if (not wglMakeCurrent(h_DC, h_RC)) then
  115.   begin
  116.     MessageBox(0, 'Unable to activate OpenGL rendering context', 'Error', MB_OK or MB_ICONERROR);
  117.     Exit;
  118.   end;
  119.  
  120.   glEnable(GL_DEPTH_TEST);
  121.   glDepthFunc(GL_LEQUAL);
  122.   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  123.  
  124.   glViewPort(0,0,clientwidth,clientheight);
  125.   glMatrixMode(GL_PROJECTION);
  126.   glLoadIdentity;
  127.   gluPerspective(60, ClientWidth/ClientHeight, 1, 1000);
  128.  
  129.   // setup nurb drawing properties
  130.   PNurb := gluNewNurbsRenderer();
  131.   gluNurbsProperty(PNurb, GLU_SAMPLING_TOLERANCE, 40.0);   // Quality - Specifies the maximum length, in pixels, to use
  132.   gluNurbsProperty(PNurb, GLU_DISPLAY_MODE, GLU_FILL);     // Fillstyle
  133. end;
  134.  
  135. procedure TForm1.FormDestroy(Sender: TObject);
  136. begin
  137.   // Makes current rendering context not current, and releases the device
  138.   // context that is used by the rendering context.
  139.   if (not wglMakeCurrent(h_DC, 0)) then
  140.     MessageBox(0, 'Release of DC and RC failed!', 'Error', MB_OK or MB_ICONERROR);
  141.  
  142.   // Attempts to delete the rendering context
  143.   if (not wglDeleteContext(h_RC)) then
  144.   begin
  145.     MessageBox(0, 'Release of rendering context failed!', 'Error', MB_OK or MB_ICONERROR);
  146.     h_RC := 0;
  147.   end;
  148.  
  149.   // Attemps to release the device context
  150.   if ((h_DC = 1) and (ReleaseDC(TWinControl(Owner).Handle, h_DC) <> 0)) then
  151.   begin
  152.     MessageBox(0, 'Release of device context failed!', 'Error', MB_OK or MB_ICONERROR);
  153.     h_DC := 0;
  154.   end;
  155. end;
  156.  
  157. procedure TForm1.FormPaint(Sender: TObject);
  158. begin
  159.   if (not wglMakeCurrent(h_DC, h_RC)) then
  160.     exit;
  161.  
  162.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
  163.   glMatrixMode(GL_MODELVIEW);
  164.   glLoadIdentity();                                       // Reset The View
  165.  
  166.   glTranslatef(0.0,0.0,-35);
  167.  
  168.   glRotatef(-45, 1.0, 0.0, 0.0);
  169.   glColor3f(0, 0.1, 0.6);
  170.  
  171.   // draw the nurb surface
  172.   gluBeginSurface(PNurb);
  173.     gluNurbsSurface(PNurb,
  174.         8, @Knots,              // No. of knots and knot array u direction
  175.         8, @Knots,              // No. of knots and knot array v direction
  176.         4 * 3,                  // Distance between control points in u dir.
  177.         3,                      // Distance between control points in v dir.
  178.         @ControlPoints,         // Control points
  179.         4, 4,                   // u and v order of surface
  180.         GL_MAP2_VERTEX_3);      // Type of surface
  181.   gluEndSurface(PNurb);
  182. end;
  183.  
  184. procedure TForm1.FormResize(Sender: TObject);
  185. begin
  186.   glViewPort(0,0,clientwidth,clientheight);
  187.   glMatrixMode(GL_PROJECTION);
  188.   glLoadIdentity;
  189.   gluPerspective(60, ClientWidth/ClientHeight, 1, 1000);
  190. end;
  191.  
  192. end.
  193.  


weiss jemand Rat?

Danke


Zuletzt geändert von Andyh am Do Nov 17, 2005 11:39, insgesamt 4-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Nov 16, 2005 13:49 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Apr 25, 2005 17:51
Beiträge: 464
Wo setzt du den Viewport?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Hallo!
BeitragVerfasst: Do Nov 17, 2005 03:35 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
Danke für den Hinweis,

aber das war es auch nicht. Dies ist ein Beispielprogramm um die Problematik aus meinem Projekt auszulagern. Dabei habe ich wirklich vergessen, den ViewPort zu setzen. Aber leider funktioniert es mit gesetztem ViewPort auch nicht.
Ich habe das Programm oben aktualisiert und ausprobiert. Auch mit ViewPort geht es nicht.

Hat noch jemand eine Idee?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Nov 17, 2005 12:17 
Offline
DGL Member

Registriert: Di Sep 06, 2005 20:40
Beiträge: 26
Wohnort: Aarhus, Denmark
Have you remembered to set a projection matrix?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Projektionsmatrix
BeitragVerfasst: Do Nov 17, 2005 12:40 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
Ich dachte, das wäre mit gluPerspective in create und resize getan.

Hat sich zufällig mal jemand den code genommen und in ein testprojekt eingefügt?

Es wäre interessant zu wissen ob es in einer anderen Umgebung läuft.

Danke


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 16 Queries | GZIP : On ]