Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

stef

Treue Seele

  • »stef« ist der Autor dieses Themas

Beiträge: 246

Wohnort: Kassel

Beruf: Softwareentwickler

  • Private Nachricht senden

1

18.01.2012, 07:08

Glanzpunkte verschwinden beim Verwenden von Texturen

Hallo
Ein wohl eher triviales OpenGL Problem. Ohne Textur hat mein Torus schöne weiße Glanzpunkte.Wenn ich eine Textur hinzufüge sind die Glanzpunkte fast nicht mehr zu sehen, obwohl ich an Licht und Material nichts geändert habe. Wie bekomme ich trotz Textur Weiße Glanzpunkte auf meinen Torus ?

Gruß

stef

Anbei mein Code und zwei Screenshots ...

C-/C++-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
182
EnableOpenGL( hWnd, &hDC, &hRC ); 
// Get function pointer if not in header file !!!glGetStringi = (P_glGetStringi) wglGetProcAddress("glGetStringi"); 
glGenBuffers = (P_glGenBuffers) wglGetProcAddress("glGenBuffers");glDeleteBuffers = (P_glDeleteBuffers) wglGetProcAddress("glDeleteBuffers"); 
glBindBuffer = (P_glBindBuffer) wglGetProcAddress("glBindBuffer");glBufferData = (P_glBufferData) wglGetProcAddress("glBufferData"); 
g_glErr = glGetError(); 
// Init OpenGL 
glEnable(GL_DEPTH_TEST); 
glShadeModel(GL_SMOOTH); 
glViewport(0, 0, g_nWidth, g_nHight); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity();gluPerspective(80.0, (double)g_nWidth/(double)g_nHight, 0.1, 400.0); 
// Init modeleview matrix 
CMatrix44 M_Modele; 
// Read version 
stringstream ss;const GLubyte* str; 
str = glGetString(GL_VENDOR);ss << "Vendor: " << str << endl; 
str = glGetString(GL_RENDERER);ss << "Renderer: " << str << endl; 
str = glGetString(GL_VERSION);ss << "OpenGL version: " << str << endl; 
i=0;ss << "Supported extensions: " << endl;while(1) 
{ 
    str = glGetStringi(GL_EXTENSIONS, i++);if(str == NULL) break;ss << str << " "; 
    str = glGetStringi(GL_EXTENSIONS, i++); 
    if(str == NULL) break;ss << str << " "; 
    str = glGetStringi(GL_EXTENSIONS, i++);if(str == NULL) break;ss << str << " "; 
    str = glGetStringi(GL_EXTENSIONS, i++); 
    if(str == NULL) break;ss << str << " "; 
    str = glGetStringi(GL_EXTENSIONS, i++);if(str == NULL) break; 
    ss << str << endl; 
}::MessageBox(hWnd, ss.str().c_str(), "OpenGL Info", MB_OK); 
// Hide Mouse Pointer 
ShowCursor(FALSE); 

// Culling 
glFrontFace(GL_CCW); // define ccw triangles as front 
glCullFace(GL_BACK); // cull (do not draw) back (cw triangles) 
glEnable(GL_CULL_FACE); // enable culling 
// Set clear (backround) color 
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 
// Modle data arrays plane 
glGenBuffers(3, unBufferID_Plane); 
vector<CVector3> vectors_p; 
vector<CVector3> normals_p; 
vector<CVector2> texture_p; 
GLsizei segments_p = 20; 
GLsizei numvertices_p = 0; 
numvertices_p = Plane2(vectors_p, normals_p, texture_p, segments_p, 500.0f, 500.0f); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[0]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_p, &vectors_p[0], GL_STATIC_DRAW); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[1]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_p, &normals_p[0], GL_STATIC_DRAW); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[2]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector2)*numvertices_p, &texture_p[0], GL_STATIC_DRAW); 
// Modle data arrays torus 
glGenBuffers(3, unBufferID_Torus); 
vector<CVector3> vectors_t; 
vector<CVector3> normals_t; 
vector<CVector2> texture_t; 
GLsizei segments_t = 100; 
GLsizei numvertices_t = 0; 
numvertices_t = Torus2(vectors_t, normals_t, texture_t, segments_t, 10.0f, 10.0f); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[0]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_t, &vectors_t[0], GL_STATIC_DRAW); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[1]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_t, &normals_t[0], GL_STATIC_DRAW); 
glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[2]);glBufferData(GL_ARRAY_BUFFER, sizeof(CVector2)*numvertices_t, &texture_t[0], GL_STATIC_DRAW); 
// Array is always enabled 
glEnableClientState( GL_VERTEX_ARRAY ); 
glEnableClientState( GL_NORMAL_ARRAY ); 
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 
g_glErr = glGetError(); //GL_INVALID_ENUM; 
// Enable light 
GLfloat light_position[] = { 0.0f, 60.0f, 0.0f, 0.0f}; 
GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 0.0f }; 
glEnable(GL_LIGHTING); 
glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f); 
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 
glEnable(GL_LIGHT0); 
// Material 
GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 0.0f }; 
GLfloat mat_diffuse_gray[] = { 1.0f, 1.0f, 1.0f, 0.0f }; 
GLfloat mat_diffuse_red[] = { 1.0f, 0.0f, 0.0f, 0.0f }; 
GLfloat mat_diffuse_green[] = { 0.0f, 1.0f, 0.0f, 0.0f }; 
GLfloat mat_diffuse_blue[] = { 0.0f, 0.0f, 1.0f, 0.0f }; 
GLfloat mat_diffuse_yello[] = { 1.0f, 1.0f, 0.0f, 0.0f }; 
GLfloat mat_shininess[] = { 50.0f }; 
glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular); 
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 

// Build texture 
GLuint textures[2]; 
glGenTextures(2, textures); 
// Setup Texture Plane 
glBindTexture(GL_TEXTURE_2D, textures[0]);ssTemp.str(""); 
ssTemp << strCmdPath;ssTemp << "Tex_Frack_01.bmp"; 
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), ssTemp.str().c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); 
if (!hBMP) // Does The Bitmap Exist? 
{ssErr.str(""); 
ssErr << "Unable to load texture from file !!!";throw ssErr.str(); 
}GetObject(hBMP, sizeof(BMP), &BMP); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); 
DeleteObject(hBMP); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
// Setup Texture Torus 
glBindTexture(GL_TEXTURE_2D, textures[1]);ssTemp.str(""); 
ssTemp << strCmdPath;ssTemp << "Tex_red.bmp"; 
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), ssTemp.str().c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );if (!hBMP) 
{ssErr.str(""); 
ssErr << "Unable to load texture from file !!!";throw ssErr.str(); 
}GetObject(hBMP, sizeof(BMP), &BMP); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); 
g_glErr = glGetError(); //GL_INVALID_ENUM; 
DeleteObject(hBMP); 
g_glErr = glGetError(); //GL_INVALID_ENUM; 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
// Enable texturing 
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
glEnable(GL_TEXTURE_2D); 
// Set fill style 
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
// Hauptnachrichtenschleife: 
QueryPerformanceFrequency((LARGE_INTEGER*)(&llFrequency));while (1) 
{ 
    QueryPerformanceCounter((LARGE_INTEGER*)(&llTime1)); 
    // check for messagesif ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
    { 
        // handle or dispatch messagesif ( msg.message == WM_QUIT ) 
        {break; 
        } else 
        { 
            TranslateMessage( &msg ); 
            DispatchMessage( &msg ); 
        } 
    } 
    // Clear buffer (color and depth) 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    // Setup view matrix 
    glMatrixMode (GL_MODELVIEW);if(bForward == true) Camera.Forward(30.0f * g_fTimeDiff); 
    glLoadMatrixf(Camera.GetCameraMatrix().m); 
    // Set position and direction of light in order to let both vectors be transformed by view matrix !!! 
    //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dirction); 
    glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
    // Build modeleview matrix plane (view * modele) 
    M_Modele = CMatrix44::Build_TranslationMatrix(0.0f, 0.0f, 0.0f) * CMatrix44::Build_RotationMatrix(0.0f, 0.0f, 0.0f); 
    glLoadMatrixf(Camera.GetCameraMatrix().m); 
    glMultMatrixf(M_Modele.m); 

    // Bind Texture Plane 
    glBindTexture(GL_TEXTURE_2D, textures[0]); 
    // draw plane 
    glEnable(GL_TEXTURE_2D); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[0]); 
    glVertexPointer(3, GL_FLOAT, 0, 0); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[1]); 
    glNormalPointer(GL_FLOAT, 0, 0); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[2]); 
    glTexCoordPointer(2, GL_FLOAT, 0, 0);for(i=0; i<segments_p; i++) 
        glDrawArrays(GL_TRIANGLE_STRIP, i * (segments_p * 2 + 2), segments_p * 2 + 2); 

    // Build modeleview matrix torus (view * modele) 
    M_Modele = CMatrix44::Build_TranslationMatrix(0.0f, 20.0f, 0.0f) * CMatrix44::Build_RotationMatrix(PI/-2.0f, g_fTimeElapsed, PI/-2.0f ); 
    glLoadMatrixf(Camera.GetCameraMatrix().m); 
    glMultMatrixf(M_Modele.m); 
    // Bind Texture Torus 
    glBindTexture(GL_TEXTURE_2D, textures[1]); 
    // draw torus 
    //glDisable(GL_TEXTURE_2D); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[0]); 
    glVertexPointer(3, GL_FLOAT, 0, 0); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[1]); 
    glNormalPointer(GL_FLOAT, 0, 0); 
    glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[2]); 
    glTexCoordPointer(2, GL_FLOAT, 0, 0); 
    g_glErr = glGetError(); //GL_INVALID_ENUM; 
    glDrawArrays(GL_TRIANGLE_STRIP, 0, numvertices_t); 
    // Swap back-buffer to front 
    SwapBuffers( hDC ); 
    // Calculate frametime 
    QueryPerformanceCounter((LARGE_INTEGER*)(&llTime2));g_fTimeDiff = ((float)llTime2 - (float)llTime1) / (float)llFrequency; 
    g_fTimeElapsed += g_fTimeDiff; 
}
»stef« hat folgende Bilder angehängt:
  • NoTexture.jpg
  • Texture.jpg
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.

DerMark

Treue Seele

Beiträge: 324

Wohnort: Emsdetten

Beruf: Softwareentwickler

  • Private Nachricht senden

2

18.01.2012, 09:02

Gibts den Code nicht auch in leserlich, so würde ich den nichtmal bei mir auf der Arbeit anfassen.

Nur mal durch Raten: Du hast sowohl fürs Licht als auch Fürs Material Eigenschaften wie Specular Farbe und auch Specular Glanz (Shine), einfach mal an denen herumschrauben könnte schon was bringen.

stef

Treue Seele

  • »stef« ist der Autor dieses Themas

Beiträge: 246

Wohnort: Kassel

Beruf: Softwareentwickler

  • Private Nachricht senden

3

18.01.2012, 10:04

Das mit dem leserlichen Code ist nicht einfach.
Mit Chrome ist nach dem copy and paste zwischen den C++ Tags alles auskommentiert und die Zeilenumbrüche fehlen.
Mit IE verschwinden die Tabs.

Ich habe den Code nochmal als RAR-File angehangen.

stef
»stef« hat folgende Datei angehängt:
  • Main.rar (4,1 kB - 72 mal heruntergeladen - zuletzt: 16.05.2024, 16:36)
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.

stef

Treue Seele

  • »stef« ist der Autor dieses Themas

Beiträge: 246

Wohnort: Kassel

Beruf: Softwareentwickler

  • Private Nachricht senden

4

18.01.2012, 10:15

@ DerMark: Der Parameter GL_SHININESS ist nur zulässig für Material und nicht für Licht.
GL_SPECULAR ist für Licht als auch Material bei mir gesetzt (siehe code aus RAR-File).

stef
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.

DerMark

Treue Seele

Beiträge: 324

Wohnort: Emsdetten

Beruf: Softwareentwickler

  • Private Nachricht senden

5

18.01.2012, 10:43

Ich bin mal so frei und formatiere den Quellcode für dich:

C-/C++-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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    MSG msg;
    HWND hWnd;  
    HDC hDC;
    HGLRC hRC;
    string strCmdLine;
    string strCmdPath;
    stringstream ssTemp;
    stringstream ssErr;
    
    // bitmap data
    HBITMAP hBMP = NULL;
    BITMAP  BMP;

    // time handling
    LONGLONG llFrequency;
    LONGLONG llTime1;
    LONGLONG llTime2;
    int i;

    GLuint unBufferID_Plane[3];
    GLuint unBufferID_Torus[3];

    try
    {
        // get command line path    
        strCmdLine.clear();
        strCmdLine.assign(::GetCommandLine());
        strCmdLine.erase(0, 1);
        while(strCmdLine[strCmdLine.length()-1] != '"')
        {
            strCmdLine.erase(strCmdLine.length()-1, 1);
        }
        strCmdLine.erase(strCmdLine.length()-1, 1);
        char* drive;
        char* dir;
        char* fname;
        char* ext;
        drive = new char[strCmdLine.length()];
        memset(drive, 0x00, strCmdLine.length());
        dir   = new char[strCmdLine.length()];
        memset(dir, 0x00, strCmdLine.length());
        fname = new char[strCmdLine.length()];
        memset(fname, 0x00, strCmdLine.length());
        ext   = new char[strCmdLine.length()];
        memset(ext, 0x00, strCmdLine.length());
        _splitpath_s( strCmdLine.c_str(), drive, strCmdLine.length(), dir, strCmdLine.length(), fname, strCmdLine.length(), ext, strCmdLine.length());
        strCmdPath.clear();
        strCmdPath.append(drive);
        strCmdPath.append(dir);
        delete drive;
        delete dir;
        delete fname;
        delete ext;

        // Init random generator
        srand( (unsigned int) time(NULL) );

        // Get full screen resolution
        HDC hdc    = ::CreateDC("DISPLAY", NULL, NULL, NULL);
        g_nWidth   = ::GetDeviceCaps(hdc, HORZRES);
        g_nHight   = ::GetDeviceCaps(hdc, VERTRES);
        g_nRefresh = ::GetDeviceCaps(hdc, VREFRESH);
        DeleteDC(hdc);

        // Globale Zeichenfolgen initialisieren
        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
        LoadString(hInstance, IDC_OPENGL, szWindowClass, MAX_LOADSTRING);
        MyRegisterClass(hInstance);

        // Set to fullscreen
        DWORD       dwExStyle;                      // Window Extended Style 
        DWORD       dwStyle;                        // Window Style 
        DEVMODE dmScreenSettings;                   // Device Mode 
        RECT WindowRect;

        WindowRect.left=(long)0;                        // Set Left Value To 0 
        WindowRect.right=(long)g_nWidth;                // Set Right Value To Requested Width 
        WindowRect.top=(long)0;                         // Set Top Value To 0 
        WindowRect.bottom=(long)g_nHight;               // Set Bottom Value To Requested Height 

        memset(&dmScreenSettings,0,sizeof(dmScreenSettings));   // Makes Sure Memory's Cleared 
        dmScreenSettings.dmSize=sizeof(dmScreenSettings);       // Size Of The Devmode Structure 
        dmScreenSettings.dmPelsWidth    = g_nWidth;             // Selected Screen Width 
        dmScreenSettings.dmPelsHeight   = g_nHight;             // Selected Screen Height 
        dmScreenSettings.dmBitsPerPel   = g_nBitsPerPixel;      // Selected Bits Per Pixel 
        dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; 

        if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
        {
            ssErr.str("");
            ssErr << "Display setting not supported !!!";
            throw ssErr.str();
        }

        dwExStyle=WS_EX_APPWINDOW;                                      // Window Extended Style 
        dwStyle=WS_POPUP;                                               // Windows Style 
        AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size 

        hInst = hInstance; // Instanzenhandle in der globalen Variablen speichern
        hWnd = CreateWindowEx(
            dwExStyle,  
            szWindowClass, 
            szTitle, 
            WS_CLIPSIBLINGS |  WS_CLIPCHILDREN  | dwStyle, 
            GetSystemMetrics(SM_CXSCREEN) / 2 - g_nWidth / 2, 
            GetSystemMetrics(SM_CYSCREEN) / 2 - g_nHight / 2, 
            g_nWidth, 
            g_nHight, 
            NULL, 
            NULL, 
            hInstance, 
            NULL);
        if(!hWnd) return FALSE;

        ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);

        // Enable OpenGL for the window
        EnableOpenGL( hWnd, &hDC, &hRC );

        // Get function pointer if not in header file !!!
        glGetStringi = (P_glGetStringi) wglGetProcAddress("glGetStringi");
        glGenBuffers = (P_glGenBuffers) wglGetProcAddress("glGenBuffers");
        glDeleteBuffers = (P_glDeleteBuffers) wglGetProcAddress("glDeleteBuffers");
        glBindBuffer = (P_glBindBuffer) wglGetProcAddress("glBindBuffer");
        glBufferData = (P_glBufferData) wglGetProcAddress("glBufferData");
        g_glErr = glGetError();

        // Init OpenGL
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_SMOOTH);
        glViewport(0, 0, g_nWidth, g_nHight);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(80.0, (double)g_nWidth/(double)g_nHight, 0.1, 400.0);

        // Init modeleview matrix
        CMatrix44 M_Modele;

        // Read version
        stringstream ss;
        const GLubyte* str;
        str = glGetString(GL_VENDOR);
        ss << "Vendor: " << str << endl;
        str = glGetString(GL_RENDERER);
        ss << "Renderer: " << str << endl;
        str = glGetString(GL_VERSION);
        ss << "OpenGL version: " << str << endl;
        i=0;
        ss << "Supported extensions: " << endl;
        while(1)
        {
            str = glGetStringi(GL_EXTENSIONS, i++);
            if(str == NULL) break;
            ss << str << "   ";
            str = glGetStringi(GL_EXTENSIONS, i++);
            if(str == NULL) break;
            ss << str << "   ";
            str = glGetStringi(GL_EXTENSIONS, i++);
            if(str == NULL) break;
            ss << str << "   ";
            str = glGetStringi(GL_EXTENSIONS, i++);
            if(str == NULL) break;
            ss << str << "   ";
            str = glGetStringi(GL_EXTENSIONS, i++);
            if(str == NULL) break;
            ss << str << endl;
        }
        ::MessageBox(hWnd, ss.str().c_str(), "OpenGL Info", MB_OK);

        // Hide Mouse Pointer
        ShowCursor(FALSE); 
        
        // Culling
        glFrontFace(GL_CCW);    // define ccw triangles as front
        glCullFace(GL_BACK);    // cull (do not draw) back (cw triangles)
        glEnable(GL_CULL_FACE); // enable culling

        // Set clear (backround) color
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );     

        // Modle data arrays plane
        glGenBuffers(3, unBufferID_Plane);
        vector<CVector3> vectors_p;
        vector<CVector3> normals_p;
        vector<CVector2> texture_p;
        GLsizei segments_p = 20;
        GLsizei numvertices_p = 0;
        numvertices_p = Plane2(vectors_p, normals_p, texture_p, segments_p, 500.0f, 500.0f);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[0]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_p, &vectors_p[0], GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[1]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_p, &normals_p[0], GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[2]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector2)*numvertices_p, &texture_p[0], GL_STATIC_DRAW);

        // Modle data arrays torus
        glGenBuffers(3, unBufferID_Torus);
        vector<CVector3> vectors_t;
        vector<CVector3> normals_t;
        vector<CVector2> texture_t;
        GLsizei segments_t = 100;
        GLsizei numvertices_t = 0;
        numvertices_t = Torus2(vectors_t, normals_t, texture_t, segments_t, 10.0f, 10.0f);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[0]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_t, &vectors_t[0], GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[1]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector3)*numvertices_t, &normals_t[0], GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[2]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(CVector2)*numvertices_t, &texture_t[0], GL_STATIC_DRAW);


        // Array is always enabled
        glEnableClientState( GL_VERTEX_ARRAY );
        glEnableClientState( GL_NORMAL_ARRAY );
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        g_glErr = glGetError(); //GL_INVALID_ENUM;

        // Enable light
        GLfloat light_position[] = { 0.0f, 60.0f, 0.0f, 0.0f};
        GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 0.0f };
        glEnable(GL_LIGHTING);
        glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f);
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
        glEnable(GL_LIGHT0);

        // Material
        GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 0.0f };
        GLfloat mat_diffuse_gray[] = { 1.0f, 1.0f, 1.0f, 0.0f };
        GLfloat mat_diffuse_red[] = { 1.0f, 0.0f, 0.0f, 0.0f };
        GLfloat mat_diffuse_green[] = { 0.0f, 1.0f, 0.0f, 0.0f };
        GLfloat mat_diffuse_blue[] = { 0.0f, 0.0f, 1.0f, 0.0f };
        GLfloat mat_diffuse_yello[] = { 1.0f, 1.0f, 0.0f, 0.0f };
        GLfloat mat_shininess[] = {  50.0f };
        glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
 
        // Build texture
        GLuint textures[2];
        glGenTextures(2, textures);

        // Setup Texture Plane
        glBindTexture(GL_TEXTURE_2D, textures[0]);
        ssTemp.str("");
        ssTemp << strCmdPath;
        ssTemp << "Tex_Frack_01.bmp";
        hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), ssTemp.str().c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
        if (!hBMP)                                                          // Does The Bitmap Exist?
        {
            ssErr.str("");
            ssErr << "Unable to load texture from file !!!";
            throw ssErr.str();
        }
        GetObject(hBMP, sizeof(BMP), &BMP); 
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
        DeleteObject(hBMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        // Setup Texture Torus
        glBindTexture(GL_TEXTURE_2D, textures[1]);
        ssTemp.str("");
        ssTemp << strCmdPath;
        ssTemp << "Tex_red.bmp";
        hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), ssTemp.str().c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
        if (!hBMP)
        {
            ssErr.str("");
            ssErr << "Unable to load texture from file !!!";
            throw ssErr.str();
        }
        GetObject(hBMP, sizeof(BMP), &BMP); 
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
        g_glErr = glGetError(); //GL_INVALID_ENUM;
        DeleteObject(hBMP);
        g_glErr = glGetError(); //GL_INVALID_ENUM;
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


        // Enable texturing
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glEnable(GL_TEXTURE_2D);

        // Set fill style   
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

        // Hauptnachrichtenschleife:
        QueryPerformanceFrequency((LARGE_INTEGER*)(&llFrequency));
        while (1)
        {
            QueryPerformanceCounter((LARGE_INTEGER*)(&llTime1));

            // check for messages
            if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
            {
                // handle or dispatch messages
                if ( msg.message == WM_QUIT ) 
                {
                    break;
                } 
                else 
                {
                    TranslateMessage( &msg );
                    DispatchMessage( &msg );
                }
            } 

            // Clear buffer (color and depth)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            
            // Setup view matrix
            glMatrixMode (GL_MODELVIEW);
            if(bForward == true) Camera.Forward(30.0f * g_fTimeDiff);
            glLoadMatrixf(Camera.GetCameraMatrix().m);

            // Set position and direction of light in order to let both vectors be transformed by view matrix !!!
            //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dirction);
            glLightfv(GL_LIGHT0, GL_POSITION, light_position);

            // Build modeleview matrix plane (view * modele)
            M_Modele = CMatrix44::Build_TranslationMatrix(0.0f, 0.0f, 0.0f) * CMatrix44::Build_RotationMatrix(0.0f, 0.0f, 0.0f);
            glLoadMatrixf(Camera.GetCameraMatrix().m);
            glMultMatrixf(M_Modele.m);
            
            // Bind Texture Plane
            glBindTexture(GL_TEXTURE_2D, textures[0]);

            // draw plane
            glEnable(GL_TEXTURE_2D);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[0]);
            glVertexPointer(3, GL_FLOAT, 0, 0);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[1]);
            glNormalPointer(GL_FLOAT, 0, 0);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Plane[2]);
            glTexCoordPointer(2, GL_FLOAT, 0, 0);
            for(i=0; i<segments_p; i++)
                glDrawArrays(GL_TRIANGLE_STRIP,  i * (segments_p * 2 + 2), segments_p * 2 + 2);


            // Build modeleview matrix torus (view * modele)
            M_Modele = CMatrix44::Build_TranslationMatrix(0.0f, 20.0f, 0.0f) * CMatrix44::Build_RotationMatrix(PI/-2.0f, g_fTimeElapsed, PI/-2.0f );
            glLoadMatrixf(Camera.GetCameraMatrix().m);
            glMultMatrixf(M_Modele.m);

            // Bind Texture Torus
            glBindTexture(GL_TEXTURE_2D, textures[1]);

            // draw torus
            glDisable(GL_TEXTURE_2D);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[0]);
            glVertexPointer(3, GL_FLOAT, 0, 0);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[1]);
            glNormalPointer(GL_FLOAT, 0, 0);
            glBindBuffer(GL_ARRAY_BUFFER, unBufferID_Torus[2]);
            glTexCoordPointer(2, GL_FLOAT, 0, 0);
            g_glErr = glGetError(); //GL_INVALID_ENUM;
            glDrawArrays(GL_TRIANGLE_STRIP,  0, numvertices_t);

            // Swap back-buffer to front
            SwapBuffers( hDC );

            // Calculate frametime
            QueryPerformanceCounter((LARGE_INTEGER*)(&llTime2));
            g_fTimeDiff = ((float)llTime2 - (float)llTime1) / (float)llFrequency;
            g_fTimeElapsed += g_fTimeDiff;
        }
    }
    catch(string e)
    {
        ::MessageBox(hWnd, e.c_str(), "ERROR !!!", MB_OK);
    }
    
    // Cleanup bitmap data
    if(hBMP) DeleteObject(hBMP); 

    // Delete vertex buffers
    glDeleteBuffers(3, unBufferID_Plane);
    glDeleteBuffers(3, unBufferID_Torus);

    // Disable OpenGL and return
    DisableOpenGL( hWnd, hDC, hRC );
    return (int) msg.wParam;
}


Hat es denn nun einen Unterschied gemacht wenn du die Parameter veränderst?

zB die 50.0f in [CODE]GLfloat mat_shininess[] = { 50.0f };[CODE] zu etwas anderem ändern. Gibt es überhaupt Specular?

Ich sehe das mat_specular sowie alle anderen Farben im W Channel jeweils 0.0 sind, in der OpenGLÖ Doku wird da als Standard wert immer 1.0 verwendet, leider kenne ich mich mit OGL zu schlecht aus um beurteilen zu können ob dies eventuell ein Problem ist. Ich würde aber dennoch versuchen dies mal zu ändern.

@BlueCobold: Warst du böse? ^^

stef

Treue Seele

  • »stef« ist der Autor dieses Themas

Beiträge: 246

Wohnort: Kassel

Beruf: Softwareentwickler

  • Private Nachricht senden

6

18.01.2012, 11:15

Vielen Dank für das Formatieren.
Gibt es da irgend einen Trick ?
Bei mir sieht der Code nach copy and paste immer zum Kot... aus.

Ich habe schon alle möglichen Farbwerte veränder und auch mit glGetError geprüft ob ich falsche Parameter übergebe.
Ohne aktivierte Textur (siehe Screenshot) ist der Glanzpunkt ja auch vorhanden.

Was meinst du mit BlueCobold und böse ?

stef
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.

DerMark

Treue Seele

Beiträge: 324

Wohnort: Emsdetten

Beruf: Softwareentwickler

  • Private Nachricht senden

7

18.01.2012, 11:59

Ich hab nur die QuellcodeDAtei geöffnet und dann per Copy&Paste alles übertragen sowie den [ c p p] Tag eingefügt, das wars, kein Trick dabei.

Wegen BC und böse: schau mal zwischen dem Startpost und dem nachfolgenden Post ;)

Wegen den Specular: Evtl ist dies das Problem:
http://www.opengl.org/resources/code/sam…tes/node63.html

Darf man fragen wieso du überhaupt noch diesen veralteten Weg gehst? Wieso nicht Shader verwenden?

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

8

18.01.2012, 12:00

@BlueCobold: Warst du böse? ^^

Nee, ich hab' nur die Specular-Einstellungen in seinem Code erst nicht gefunden und hatte dann keine Zeit mehr, wollte den Quatsch aber nicht stehenlassen.
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

stef

Treue Seele

  • »stef« ist der Autor dieses Themas

Beiträge: 246

Wohnort: Kassel

Beruf: Softwareentwickler

  • Private Nachricht senden

9

18.01.2012, 12:51

@DerMark: BINGO !!! Vielen Dank. Der Torus klänzt jetzt auch mit Textur.
Bezüglich Shader: Ich möchte erst mal mit der Fixed Pipe die basics grob durchgehen.
Dann kommen die Shader drann.



@BlueCobold: Was genau hast du denn geschrieben das es der Zensur zum Opfer viel ?

Gruß

stef
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.

Werbeanzeige