,  , OpenGL

 
 
 4.69/13:  :  - 13,   - 4.69
Ammaximus
3 / 3 / 0
: 15.01.2009
: 26
1

OpenGL

06.11.2009, 05:51. 2268. 8
( )

, , ? pushmatrix, . . ?
( 256x256 space.bmp)
C++
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
#include <windows.h>        // Ç*ãîëîâî÷*ûé ô*éë äëÿ Windows
#include <gl\gl.h>      // Ç*ãîëîâî÷*ûé ô*éë äëÿ OpenGL32 áèáëèîòåêè
#include <gl\glu.h>     // Ç*ãîëîâî÷*ûé ô*éë äëÿ GLu32 áèáëèîòåêè
#include <gl\glaux.h>       // Ç*ãîëîâî÷*ûé ô*éë äëÿ GLaux áèáëèîòåêè
#include <GL\glut.h>
 
static HGLRC hRC;       // Ïîñòîÿ**ûé êî*òåêñò ðå*äåðè*ã*
static HDC hDC;         // Ïðèâ*ò*ûé êî*òåêñò óñòðîéñòâ* GDI
 
BOOL    keys[256];      // Ì*ññèâ äëÿ ïðîöåäóðû îáð*áîòêè êë*âè*òóðû
 
   GLfloat light_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_position[] = { 3.0, 2.0, 48.0, 0.0 }; 
 
GLfloat xrot;           // Âð*ùå*èå X
GLfloat yrot;           // Y
GLfloat zrot;           // Z
 
GLuint  texture[1];     // Ìåñòî äëÿ îä*îé òåêñòóðû
// Ç*ãðóçê* ê*ðòè*êè è êî*âåðòèðîâ**èå â òåêñòóðó
 
GLvoid LoadGLTextures(){
    // Ç*ãðóçê* ê*ðòè*êè
    AUX_RGBImageRec *texture1;
    texture1 = auxDIBImageLoad("space.bmp");
    // Ñîçä**èå òåêñòóðû
    glGenTextures(1, &texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
}GLvoid InitGL(GLsizei Width, GLsizei Height){
    LoadGLTextures();           // Ç*ãðóçê* òåêñòóð
    glEnable(GL_TEXTURE_2D);        // Ð*çðåøå*èå **ëîæå*èå òåêñòóðû
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(450.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //LIGHT//
    /* ?????? ????????? ????????? ????? */ 
   glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); 
   glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); 
   glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular); 
   glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
    /* ???????? ????????? ? ?????? ???????? */   
  glEnable (GL_LIGHTING); 
  glEnable (GL_LIGHT0);
}
GLvoid DrawGLScene(GLvoid){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-5.0f);
    glPushMatrix();
    glTranslatef(2.6f,0.0f,0.0f);
    glRotatef(70,1.0f,0.0f,0.0f);
    glutSolidSphere(1,10,10);
    glPopMatrix();
    glRotatef(xrot,1.0f,0.0f,0.0f);     // Âð*ùå*èå ïî îñè X
//  glRotatef(yrot,0.0f,1.0f,0.0f);     // Âð*ùå*èå ïî îñè Y
//  glRotatef(zrot,0.0f,0.0f,1.0f);     // Âð*ùå*èå ïî îñè Z
    glPushMatrix();
    glLoadIdentity();
    glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
    glPopMatrix();
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
 
                // Ïåðåä*ÿÿ ãð**ü
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Âåðõ ëåâî
 
                // Ç*ä*ÿÿ ãð**ü
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Íèç ëåâî
 
                // Âåðõ*ÿÿ ãð**ü
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    
                // Íèæ*ÿÿ ãð**ü
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ïð*âî
 
                // Ïð*â*ÿ ãð**ü
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ëåâî
 
                // Ëåâ*ÿ ãð**ü
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
 
    glEnd();
    glLoadIdentity();
    glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
///// <------
    glutSwapBuffers();
    glutPostRedisplay(); 
    xrot+=0.1f;         // Îñü âð*ùå*èÿ X
    yrot+=0.1f;         // Îñü âð*ùå*èÿ Y
    zrot+=0.1f;         // Îñü âð*ùå*èÿ Z
 
}
int main (int argc, char** argv){
   glutInit(&argc, argv); 
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
   glutInitWindowSize (500, 500); 
   glutCreateWindow ("ßùèê"); 
   InitGL (30,30); 
   glutDisplayFunc (DrawGLScene); 
   glutMainLoop(); 
   return 0; 
return 0;
}
0
? .
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
06.11.2009, 05:51
:

opengl 8 ?
opengl 8 ? ...

C++/opengl. openGL
opengl - windows - . linux ...

(2 ) OpenGL Programming Guide, Version 4.3, 8th Edition - OpenGL
http://www.cyberforum.ru/opengl/thread1551398.html ...

opengl, opengl
#include &lt;windows.h&gt; #include &quot;stdafx.h&quot; #include &lt;gl/gl.h&gt; #include &lt;gl/glu.h&gt; #include...

OpenGL. 1. OpenGL-
#include &lt;GL\glut.h&gt; void DrawLine() { ...

8
[Igor]
716 / 468 / 128
: 24.12.2008
: 3,910
06.11.2009, 18:13 2
SwapBuffers(h_DC);
0
Ammaximus
3 / 3 / 0
: 15.01.2009
: 26
07.11.2009, 00:55  [] 3
swap. ( ), a .
, .
, , .
Delphi
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
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, OpenGL, ComCtrls, Menus;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    TrackBarX: TTrackBar;
    TrackBarY: TTrackBar;
    TrackBarZ: TTrackBar;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure TrackBarXChange(Sender: TObject);
    procedure TrackBarYChange(Sender: TObject);
    procedure TrackBarZChange(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
DC:hdc;
hrc:hdc;
TimerFlag:boolean=false;
fSpeedX:GLfloat=0;
fSpeedY:GLfloat=0;
fSpeedZ:GLfloat=0;
 
implementation
 
{$R *.dfm}
 
procedure SetDCPixelFormat (hdc : HDC);    
var
pfd : TPixelFormatDescriptor;
nPixelFormat : Integer;
begin
FillChar (pfd, SizeOf (pfd), 0);
pfd.dwFlags :=PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
nPixelFormat :=ChoosePixelFormat (hdc, @pfd);
SetPixelFormat(hdc, nPixelFormat, @pfd);
end;
 
procedure Tform1.FormCreate(Sender: TObject);
begin
DC := GetDC (Handle);
SetDCPixelFormat(DC);
hrc := wglCreateContext(DC);
wglMakeCurrent(DC, hrc);
glClearColor (0.8, 0.8, 0.8, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity;
glFrustum (-1, 1, -1, 1, 2, 20);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity;
glTranslatef(0.0, 0.0, -6.0);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
if TimerFlag then
  begin
    glEnable (GL_DEPTH_TEST);
    timer1.enabled:=false;
    TimerFlag:=false;
    Button1.Caption :='Ç*ïóñòèòü';
  end
else
  begin
    glEnable (GL_DEPTH_TEST);
    timer1.enabled:=true;
    TimerFlag:=true;
    Button1.Caption :='Ñòîï';
 
  end;
end;
 
procedure TForm1.Timer1Timer(Sender: TObject);
begin
glPushMatrix();
glLoadIdentity();
 
glPopMatrix();
glRotatef(fSpeedX, 1.0, 0.0, 0.0);
glRotatef(fSpeedY, 0.0, 1.0, 0.0);
glRotatef(fSpeedZ, 0.0, 0.0, 1.0);
 
SwapBuffers(DC);
 
InvalidateRect(Handle, nil, False);
end;
 
procedure TForm1.FormPaint(Sender: TObject);
begin
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLES);
        glColor3f(1.0,0.0,0.0);
        glVertex3f( 0.0, 1.0, 0.0);
        glColor3f(1.0,1.0,0.0);
        glVertex3f(-1.0,-1.0, 1.0);
        glColor3f(0.0,0.0,1.0);
        glVertex3f( 1.0,-1.0, 1.0);
            glColor3f(1.0,0.0,0.0);
        glVertex3f( 0.0, 1.0, 0.0);
        glColor3f(0.0,0.0,1.0);
        glVertex3f( 1.0,-1.0, 1.0);
        glColor3f(0.0,1.0,0.0);
        glVertex3f( 1.0,-1.0, -1.0);
            glColor3f(1.0,0.0,0.0);
        glVertex3f( 0.0, 1.0, 0.0);
        glColor3f(0.0,1.0,0.0);
        glVertex3f( 1.0,-1.0, -1.0);
        glColor3f(0.8,0.4,0.5);
        glVertex3f(-1.0,-1.0, -1.0);
            glColor3f(1.0,0.0,0.0);
        glVertex3f( 0.0, 1.0, 0.0);
        glColor3f(0.8,0.4,0.5);
        glVertex3f(-1.0,-1.0,-1.0);
        glColor3f(1.0,1.0,0.0);
        glVertex3f(-1.0,-1.0, 1.0);
 
    glEnd();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
wglMakeCurrent(0, 0);
wglDeleteContext(hrc);
ReleaseDC (Handle, DC);
DeleteDC (DC);
 
end;
 
procedure TForm1.TrackBarXChange(Sender: TObject);
begin
 fSpeedX:=0.5*TrackBarX.Position;
end;
procedure TForm1.TrackBarYChange(Sender: TObject);
begin
 fSpeedY:=0.5*TrackBary.Position;
end;
 
procedure TForm1.TrackBarZChange(Sender: TObject);
begin
 fSpeedZ:=0.5*TrackBarZ.Position;
end;
 
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
    glEnable (GL_LIGHTING);
    glEnable (GL_LIGHT0);
end;
 
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
    glDisable (GL_LIGHTING);
    glDisable (GL_LIGHT0);
end;
 
end.
0
snake32
1660 / 1114 / 195
: 26.02.2009
: 4,122
: 5
07.11.2009, 05:09 4
Ammaximus, - glNormal3f();
0
Adler
79 / 79 / 19
: 07.05.2009
: 316
07.11.2009, 21:37 5
, ... .
0
[Igor]
716 / 468 / 128
: 24.12.2008
: 3,910
07.11.2009, 22:22 6
Delphi . glNormal3f C++.
0
Ammaximus
3 / 3 / 0
: 15.01.2009
: 26
07.11.2009, 23:15  [] 7
, , . ?
0
[Igor]
716 / 468 / 128
: 24.12.2008
: 3,910
08.11.2009, 00:53 8
:
Delphi
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
    glPushMatrix();
      glBegin(GL_QUADS);
        glVertex3f(-0.3, -0.3, 0.3);
        glVertex3f(-0.3, 0.3, 0.3);
        glVertex3f(0.3, 0.3, 0.3);
        glVertex3f(0.3, -0.3, 0.3);
      glEnd();
    glPopMatrix();
 
    glPushMatrix();
      glRotate(90, 1.0, 0.0, 0.0);
        glBegin(GL_QUADS);
          glVertex3f(-0.3, -0.3, 0.3);
          glVertex3f(-0.3, 0.3, 0.3);
          glVertex3f(0.3, 0.3, 0.3);
          glVertex3f(0.3, -0.3, 0.3);
        glEnd();
    glPopMatrix();
 
    glPushMatrix();
      glRotate(180, 1.0, 0.0, 0.0);
        glBegin(GL_QUADS);
          glVertex3f(-0.3, -0.3, 0.3);
          glVertex3f(-0.3, 0.3, 0.3);
          glVertex3f(0.3, 0.3, 0.3);
          glVertex3f(0.3, -0.3, 0.3);
        glEnd();
    glPopMatrix();
 
    glPushMatrix();
      glRotate(270, 1.0, 0.0, 0.0);
        glBegin(GL_QUADS);
          glVertex3f(-0.3, -0.3, 0.3);
          glVertex3f(-0.3, 0.3, 0.3);
          glVertex3f(0.3, 0.3, 0.3);
          glVertex3f(0.3, -0.3, 0.3);
        glEnd();
    glPopMatrix();
 
    glPushMatrix();
      glRotate(90, 0.0, 1.0, 0.0);
        glBegin(GL_QUADS);
          glVertex3f(-0.3, -0.3, 0.3);
          glVertex3f(-0.3, 0.3, 0.3);
          glVertex3f(0.3, 0.3, 0.3);
          glVertex3f(0.3, -0.3, 0.3);
        glEnd();
    glPopMatrix();
 
    glPushMatrix();
      glRotate(270, 0.0, 1.0, 0.0);
        glBegin(GL_QUADS);
          glVertex3f(-0.3, -0.3, 0.3);
          glVertex3f(-0.3, 0.3, 0.3);
          glVertex3f(0.3, 0.3, 0.3);
          glVertex3f(0.3, -0.3, 0.3);
        glEnd();
    glPopMatrix();
3
glNormal3f
Delphi
1
2
3
4
5
6
7
  glBegin(GL_QUADS);
    glNormal3f( 0.0, 0.0,-0.3);
    glVertex3f(-0.3, -0.3, -0.3);
    glVertex3f(-0.3,  0.3, -0.3);
    glVertex3f( 0.3,  0.3, -0.3);
    glVertex3f( 0.3, -0.3, -0.3);
  glEnd;
.
0
Ammaximus
3 / 3 / 0
: 15.01.2009
: 26
08.11.2009, 01:43  [] 9
, . http://pmg.org.ru/basic3d/math.htm . , .
C++
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
#include <windows.h>        // Ç*ãîëîâî÷*ûé ô*éë äëÿ Windows
#include <gl\gl.h>      // Ç*ãîëîâî÷*ûé ô*éë äëÿ OpenGL32 áèáëèîòåêè
#include <gl\glu.h>     // Ç*ãîëîâî÷*ûé ô*éë äëÿ GLu32 áèáëèîòåêè
#include <gl\glaux.h>       // Ç*ãîëîâî÷*ûé ô*éë äëÿ GLaux áèáëèîòåêè
#include <GL\glut.h>
 
static HGLRC hRC;       // Ïîñòîÿ**ûé êî*òåêñò ðå*äåðè*ã*
static HDC hDC;         // Ïðèâ*ò*ûé êî*òåêñò óñòðîéñòâ* GDI
 
BOOL    keys[256];      // Ì*ññèâ äëÿ ïðîöåäóðû îáð*áîòêè êë*âè*òóðû
 
   GLfloat light_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 
   GLfloat light_position[] = { 9.0, 6.0, 0.0, 0.0 }; 
 
GLfloat xrot;           // Âð*ùå*èå X
GLfloat yrot;           // Y
GLfloat zrot;           // Z
 
GLfloat nx,ny,nz;
GLuint  texture[1];     // Ìåñòî äëÿ îä*îé òåêñòóðû
// Ç*ãðóçê* ê*ðòè*êè è êî*âåðòèðîâ**èå â òåêñòóðó
 
GLvoid LoadGLTextures(){
    // Ç*ãðóçê* ê*ðòè*êè
    AUX_RGBImageRec *texture1;
    texture1 = auxDIBImageLoad("space.bmp");
    // Ñîçä**èå òåêñòóðû
    glGenTextures(1, &texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
}
 
GLvoid InitGL(GLsizei Width, GLsizei Height){
    LoadGLTextures();           // Ç*ãðóçê* òåêñòóð
    glEnable(GL_TEXTURE_2D);        // Ð*çðåøå*èå **ëîæå*èå òåêñòóðû
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0);
 
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(450.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //LIGHT//
 
    glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); 
    glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); 
    glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular); 
    glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
 
    glEnable (GL_LIGHTING); 
    glEnable (GL_LIGHT0);
 
}
GLvoid DrawGLScene(GLvoid){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-5.0f);
    
    glPushMatrix();
    glTranslatef(2.6f,0.0f,0.0f);
    glRotatef(70,1.0f,0.0f,0.0f);
    glutSolidSphere(1,70,70);
    glPopMatrix();
 
    glRotatef(xrot,1.0f,0.0f,0.0f);     // Âð*ùå*èå ïî îñè X
    glRotatef(yrot,0.0f,1.0f,0.0f);     // Âð*ùå*èå ïî îñè Y
    glRotatef(zrot,0.0f,0.0f,1.0f);     // Âð*ùå*èå ïî îñè Z
    
    glPushMatrix();
    glLoadIdentity();
    glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
    glPopMatrix();
 
    glBindTexture(GL_TEXTURE_2D, texture[0]);
 
    glBegin(GL_QUADS);
 
                // Ïåðåä*ÿÿ ãð**ü
 
    glNormal3f(0,0,1);
    
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ëåâî 1
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ïð*âî 2
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Âåðõ ïð*âî 3
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Âåðõ ëåâî
 
                // Ç*ä*ÿÿ ãð**ü
    glNormal3f(0,0,-1);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Íèç ëåâî
 
                // Âåðõ*ÿÿ ãð**ü
    glNormal3f(0,1,0);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    
                // Íèæ*ÿÿ ãð**ü
    glNormal3f(0,-1,0);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ïð*âî
 
                // Ïð*â*ÿ ãð**ü
    glNormal3f(1,0,0);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Âåðõ ëåâî
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Íèç ëåâî
 
                // Ëåâ*ÿ ãð**ü
    glNormal3f(-1,0,0);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Íèç ëåâî
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Íèç ïð*âî
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Âåðõ ïð*âî
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Âåðõ ëåâî
 
    glEnd();
 
    glLoadIdentity();
    glLightfv (GL_LIGHT0, GL_POSITION, light_position); 
///// <------
    glutSwapBuffers();
    glutPostRedisplay(); 
    xrot+=0.1f;         // Îñü âð*ùå*èÿ X
    yrot+=0.1f;         // Îñü âð*ùå*èÿ Y
    zrot+=0.1f;         // Îñü âð*ùå*èÿ Z
    
}
 
int main (int argc, char** argv){
 
   glutInit(&argc, argv); 
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
   glutInitWindowSize (500, 500); 
   glutCreateWindow ("ßùèê"); 
 
   InitGL (30,30); 
   glutDisplayFunc (DrawGLScene); 
 
   glutMainLoop(); 
   return 0; 
return 0;
}
2
08.11.2009, 01:43
MoreAnswers
37091 / 29110 / 5898
: 17.06.2006
: 43,301
08.11.2009, 01:43

OpenGL - VS2008 OpenGL (Glut)
3d ? ...

OpenGL + GlTools OpenGL
4 3 . : void RenderScene(void) {...

OpenGL (OpenGL + )
! . . . ...




:
9

- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
@Mail.ru