Autor Beitrag
Freezer-X
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24

Win XP
d7 pers
BeitragVerfasst: Do 05.08.04 17:02 
Ja wollte meinen heissgliebten würfel ein paar texturen verpassen (soll halt wie ein richtiger spielwürfel aussehen) allerdings wird nur die Textur angezeigt die auch zuletzt geladen wurde (in dem fall die Sechs), das allerdings auf allen flächen obwohl ich unterschiedliche variablen benutzt habe. hier mal der code:
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:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
unit Unit1;

interface

uses
  Windows,Classes, Controls, Forms,
  opengl12, textures;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure SetDCPixelFormat(Handle: HDC);
    procedure InitGL;
    procedure DrawScene;
    procedure ApplicationEvents1Idle(Sender: TObject;
  var Done: Boolean);
    procedure InitTextures;

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  h_DC:hdc;
  hRC:HGLRC;
  rotateX:single;
  tex1:cardinal;
  tex2:cardinal;
  tex3:cardinal;
  tex4:cardinal;
  tex5:cardinal;
  tex6:cardinal;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
InitOpenGL;
h_DC:=GetDC(handle);
SetDCpixelformat(h_DC);
hRC:=wglcreateContext(h_DC);
wglMakecurrent(h_DC,hrc);
InitGL;
Application.OnIdle:=Applicationevents1idle;
glEnable(GL_TEXTURE_2D);
InitTextures;

end;


procedure TForm1.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 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,100);
  glMatrixMode(GL_MODELVIEW);
end;

procedure TForm1.DrawScene;
begin
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity;
  glTranslate(0,0,-10);
  glRotate(RotateX,1,0.5,0.3);
  GLBegin(GL_quads);
  glbindtexture(gl_texture_2d,tex1);
  glcolor3f(0.3,0.7,0.6);
  glTexCoord2f(1,0); glvertex3f(-1,0,0); //Vorderseite
  glTexCoord2f(1,1); glvertex3f(1,0,0);
  glTexCoord2f(0,1); glvertex3f(1,2,0);
  glTexCoord2f(0,0); glvertex3f(-1,2,0);
  glend;
  glbegin(gl_quads);
  glbindtexture(gl_texture_2d,tex2);
  glcolor3f(0.5,0.7,0.6);
  glTexCoord2f(1,0); glvertex3f(-1,0,-2);  //Rückseite
  glTexCoord2f(1,1); glvertex3f(1,0,-2);
  glTexCoord2f(0,1); glvertex3f(1,2,-2);
  glTexCoord2f(0,0); glvertex3f(-1,2,-2);
  glend;
  glbegin(gl_quads);
  glbindtexture(gl_texture_2d,tex3);
  glcolor3f(0.2,0.2,0.3);
  glTexCoord2f(1,0); glvertex3f(1,0,0);    //rechte seite
  glTexCoord2f(1,1); glvertex3f(1,0,-2);
  glTexCoord2f(0,1); glvertex3f(1,2,-2);
  glTexCoord2f(0,0); glvertex3f(1,2,0);
  glbindtexture(gl_texture_2d,tex4);
  glcolor3f(0.7,0.9,0.3);
  glTexCoord2f(1,0); glvertex3f(-1,0,0);          //linke seite
  glTexCoord2f(1,1); glvertex3f(-1,0,-2);
  glTexCoord2f(0,1); glvertex3f(-1,2,-2);
  glTexCoord2f(0,0); glvertex3f(-1,2,0);
  glbindtexture(gl_texture_2d,tex5);
  glcolor3f(0.3,0.9,0.3);
  glTexCoord2f(1,0); glvertex3f(-1,0,0);  //unterseite
  glTexCoord2f(1,1); glvertex3f(1,0,0);
  glTexCoord2f(0,1); glvertex3f(1,0,-2);
  glTexCoord2f(0,0); glvertex3f(-1,0,-2);
  glbindtexture(gl_texture_2d,tex6);
  glcolor3f(1,0.1,0);
  glTexCoord2f(1,0); glvertex3f(-1,2,0);     //oberseite
  glTexCoord2f(1,1); glvertex3f(1,2,0);
  glTexCoord2f(0,1); glvertex3f(1,2,-2);
  glTexCoord2f(0,0); glvertex3f(-1,2,-2);
  glend;
  SwapBuffers(h_DC);
  RotateX:=RotateX + 0.1;
if RotateX>360 then
  RotateX:=RotateX - 360;

end;

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

procedure Tform1.InitTextures;
begin
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel1.bmp',tex1,false);
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel2.bmp',tex2,false);
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel3.bmp',tex3,false);
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel4.bmp',tex4,false);
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel5.bmp',tex5,false);
LoadTexture('C:\Dokumente und Einstellungen\Freezer-X\Desktop\Delphi_games_Programming\OpenGL\Tut_Delphi_Dateien\3d Quadrat\bilder\wuerfel6.bmp',tex6,false);
end;
end.


Ich hoffe mir kann jemand helfen sonst verzweifel ich noch daran da ich mit opengl noch nicht genügend erfahrung hab um zu wissen woran es liegen könnte.


Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt.
Blackbird
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Do 05.08.04 17:49 
Hallo Freezer:
Der Fehler liegt darin, dass du glBindtexture() innerhalb des GLBegin()/GLEnd Blocks aufrufst. Das gehöhrt da nicht hin, sondern davor...

Thomas
Freezer-X Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24

Win XP
d7 pers
BeitragVerfasst: Do 05.08.04 20:25 
Stimmt hast recht danke. Soviel stress wegen sowas :oops: ^^"