Autor Beitrag
Slowmo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 29

Suse Linux 10.1
Lazarus v.0.9.18
BeitragVerfasst: Do 17.11.05 18:43 
Ich habe ein OpenGL-Programm programmiert in welchem man eine Kugel mit einer Textur frei drehen kann. Auf meinem Computer funktioniert das auch ohne Probleme, doch auf anderen PC's kommt am Anfang sofort ein Fehler:

"System Error. Code 2000. Das Pixelformat ist ungültig."

Ich habe das Programm nun schon auf mehreren PC getestet und habe den Verdacht, dass das Betriebssystem ausschlaggebend ist: auf Windows XP Prof funktioniert das Programm auf XP Home und 2000 nicht. Woran könnte das liegen.

Hier noch etwas Quelltext:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
  procedure SetDCPixelFormat(Handle: HDC);
  var
    nPixelFormat: GLUint;
  const
    pfd: PIXELFORMATDESCRIPTOR = (
        nSize: sizeof( PIXELFORMATDESCRIPTOR );
        nVersion: 1;
        dwFlags: PFD_DRAW_TO_WINDOW
        or PFD_SUPPORT_OPENGL
        or PFD_DOUBLEBUFFER;
        iPixelType: PFD_TYPE_RGBA;
        cColorBits: 16;
        cRedBits: 0;
        cRedShift: 0;
        cGreenBits: 0;
        cBlueBits: 0;
        cBlueShift: 0;
        cAlphaBits: 0;
        cAlphaShift: 0;
        cAccumBits: 0;
        cAccumRedBits: 0;
        cAccumGreenBits: 0;
        cAccumBlueBits: 0;
        cAccumAlphaBits: 0;
        cDepthBits: 16;
        cStencilBits: 0;
        cAuxBuffers: 0;
        iLayerType: PFD_MAIN_PLANE;
        bReserved: 0;
        dwLayerMask: 0;
        dwVisibleMask: 0;
        dwDamageMask: 0
    );
  begin
    nPixelFormat:=ChoosePixelFormat(h_DC, @pfd);
    SetPixelFormat(h_DC,nPixelFormat,@pfd);
  end;

procedure LoadTextures();
begin
fTexture := TglBitmap2D.Create; // Instanz der Klasse erstellen
fTexture.LoadFromFile('texture.bmp'); // Datei laden
fTexture.GenTexture; // geladene Textur an OpenGL übergeben
end;

{Prozedur die die Grundeinstellungen von OpenGl einstellt}
procedure TForm1.InitGL;
begin
  glClearColor(0,0,0,0);
  glClearDepth(1);
  glDepthFunc(GL_LESS);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);


  glViewport(0,0,Width,Height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45,Width/Height,1,200);
  glMatrixMode(GL_MODELVIEW);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //OpenGl intitialisieren
  InitOpenGl;
  //DeviceContext des Formulars
  h_DC:=GetDC(Form1.Handle);
  //Pixelformat
  SetDCPixelFormat(h_DC);
  //ZeichenKontext erstellen
  hRC:=CreateRenderingContext( h_DC,
                               [opDoubleBuffered],
                               32,
                               24,
                               0,0,0,
                               0);

  ActivateRenderingContext(h_DC,hRC);

  InitGl;
  //Texturen in den Speicher schreiben
  LoadTextures;
  Application.OnIdle := IdleHandler;
end;

procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
begin
  DrawScene;
  Done:=False;
end;

procedure TForm1.DrawScene;
var Quadric: PGLUQuadric;
begin
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  //Hier wird die Scene gezeichnet

    glTranslatef( 0, 0, 0);

    Quadric:=gluNewQuadric;
    gluQuadricTexture(Quadric, TRUE);

    fTexture.Bind;
    gluSphere(Quadric, 30, 180, 180);


  SwapBuffers(h_DC);
  Sleep(5);
end;


Zuletzt bearbeitet von Slowmo am Do 17.11.05 19:00, insgesamt 2-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 17.11.05 18:46 
Mein Auto fährt nicht, woran liegt das?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: Do 17.11.05 18:47 
Das liegt daran, dass du gar kein Auto hast ;)
Slowmo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 29

Suse Linux 10.1
Lazarus v.0.9.18
BeitragVerfasst: Do 17.11.05 19:01 
Sorry, ich hatte aus Versehen auf den Abschicken-Button gedrückt bevor ich fertig mit schreiben war.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 17.11.05 19:19 
Soweit ich das überblicke nutzt du die DGL-Units ...

IIRC braucht dort das Pixel-Format nicht explizit gesetzt zu werden, bin mir da aber ATM nicht ganz sicher.

Wenn versuch sicherzustellen, dass Du kompatible Formate nutzt ... d.h. wenn Du von OGL 32\24 bit erwartest, solltest Du auch ein 32-bit-Format bereitstellen und kein 16-bittiges ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: Fr 18.11.05 08:47 
Als kleine Anmerkung. OpenGL hat nichts mit dem Betriebssystem zu tun. Das ist alleine Sache des Grafikkartentreibers.

Kann mich BenBe aber anschließen. Das expliziete Setzen des Pixelformates wird bereits in der Methode CreateRenderContext erledigt und muss somit nicht selber gemacht werden. Denke mal, dass das bereits das Problem sein sollte.

Eigentlich spielt es keine Rolle ob du beim Auswählen des Pixelformates 16, 24 oder 32 Bit angibst. Es wird eigentlich grundsätzlich immer die Farbtiefe benutzt die auch im Windows eingestellt ist. Wenn man in den Vollbildmodus wechselt, dann sollte man da aber schon drauf achten. Aber auch hierbeit gilt. Das letzte Wort hat der Treiber. Und der kann es auch ermöglichen, dass bei 32 Farbtiefe ein 16 Bit RC erstellt wird. Dennoch stimmt es schon. 32 Bit anzugeben ist da generell immer besser.

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
Slowmo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 29

Suse Linux 10.1
Lazarus v.0.9.18
BeitragVerfasst: Fr 18.11.05 15:00 
OK, danke das war das Problem, und danke für die zusätzlichen Ausführungen, ich lerne immer gerne was dazu (Ich hab noch sehr wenig mit OpenGl gearbeitet).