質問編集履歴
3
削除できないので、削除リクエストが失敗
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,181 +1,4 @@
|
|
1
|
-
最近、C言語で SDL2 と OpenGL を勉強はじめました。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
OpenGLで画像を描画したいと思います。でも結果は画像の部分が白いしかないです。画像が描画されないです。
|
6
|
-
|
7
|
-
![イメージ説明](7be407cfacf910b1829c85dcdca3119c.png)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
削除しました
|
12
|
-
|
13
|
-
```
|
2
|
+
```ここに言語を入力
|
14
|
-
|
15
|
-
|
3
|
+
削除できないので、削除リクエストが失敗
|
16
|
-
|
17
4
|
```
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
コード:
|
22
|
-
|
23
|
-
```c
|
24
|
-
|
25
|
-
#include <SDL2/SDL.h>
|
26
|
-
|
27
|
-
#include <SDL2/SDL_opengl.h>
|
28
|
-
|
29
|
-
#include <SDL2/SDL_image.h>
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#define WINDOW_W 640
|
34
|
-
|
35
|
-
#define WINDOW_H 480
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
SDL_Window* window;
|
40
|
-
|
41
|
-
SDL_Event event;
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
SDL_GLContext context;
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
int main(int argc, char* argv[]) {
|
50
|
-
|
51
|
-
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
52
|
-
|
53
|
-
SDL_Log("Error: SDL failed to initialize. %s\n", SDL_GetError());
|
54
|
-
|
55
|
-
return 1;
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
window = SDL_CreateWindow("project-script", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_W, WINDOW_H, SDL_WINDOW_OPENGL);
|
66
|
-
|
67
|
-
if (window == NULL) {
|
68
|
-
|
69
|
-
SDL_Log("Error: Window failed to create. %s\n", SDL_GetError());
|
70
|
-
|
71
|
-
return 1;
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
context = SDL_GL_CreateContext(window);
|
78
|
-
|
79
|
-
if (context == NULL) {
|
80
|
-
|
81
|
-
SDL_Log("Error: context failed to create. %s\n", SDL_GetError());
|
82
|
-
|
83
|
-
return 1;
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
glEnable(GL_TEXTURE_2D);
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
// Load Image
|
94
|
-
|
95
|
-
GLuint textureID = 0;
|
96
|
-
|
97
|
-
SDL_Surface* ImageSurface = IMG_Load("MyImage.jpg");
|
98
|
-
|
99
|
-
glGenTextures(1, &textureID);
|
100
|
-
|
101
|
-
glBindTexture(GL_TEXTURE_2D, textureID);
|
102
|
-
|
103
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ImageSurface->w, ImageSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ImageSurface->pixels);
|
104
|
-
|
105
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
106
|
-
|
107
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
int quit = 0;
|
112
|
-
|
113
|
-
while (quit == 0) {
|
114
|
-
|
115
|
-
while (SDL_PollEvent(&event)) {
|
116
|
-
|
117
|
-
if (event.type == SDL_QUIT) quit = 1;
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
glClearColor(0 ,0 ,0, 1);
|
124
|
-
|
125
|
-
glClear(GL_COLOR_BUFFER_BIT);
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
glBindTexture(GL_TEXTURE_2D, textureID);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
glBegin(GL_QUADS);
|
134
|
-
|
135
|
-
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
|
136
|
-
|
137
|
-
glTexCoord2f(1, 0); glVertex3f(ImageSurface->w, 0, 0);
|
138
|
-
|
139
|
-
glTexCoord2f(1, 1); glVertex3f(ImageSurface->w, ImageSurface->h, 0);
|
140
|
-
|
141
|
-
glTexCoord2f(0, 1); glVertex3f(0, ImageSurface->h, 0);
|
142
|
-
|
143
|
-
glEnd();
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
SDL_GL_SwapWindow(window);
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
glDisable(GL_TEXTURE_2D);
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
glDeleteTextures(1, &textureID);
|
158
|
-
|
159
|
-
SDL_GL_DeleteContext(context);
|
160
|
-
|
161
|
-
SDL_DestroyWindow(window);
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
IMG_Quit();
|
166
|
-
|
167
|
-
SDL_Quit();
|
168
|
-
|
169
|
-
return 0;
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
```
|
176
|
-
|
177
|
-
何が間違っているでしょうか
|
178
|
-
|
179
|
-
別の方法などがあったら教えてぐださい。
|
180
|
-
|
181
|
-
ありがとうございます。
|
2
また、間違いところを。。。
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,8 +154,6 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
-
SDL_GL_DeleteContext(context);
|
158
|
-
|
159
157
|
glDeleteTextures(1, &textureID);
|
160
158
|
|
161
159
|
SDL_GL_DeleteContext(context);
|
1
間違いところ見つかった
test
CHANGED
File without changes
|
test
CHANGED
@@ -144,11 +144,7 @@
|
|
144
144
|
|
145
145
|
|
146
146
|
|
147
|
-
SDL_GL_SwapWindow(window);
|
147
|
+
SDL_GL_SwapWindow(window);
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
SDL_GL_DeleteContext(context);
|
152
148
|
|
153
149
|
}
|
154
150
|
|
@@ -157,6 +153,8 @@
|
|
157
153
|
glDisable(GL_TEXTURE_2D);
|
158
154
|
|
159
155
|
|
156
|
+
|
157
|
+
SDL_GL_DeleteContext(context);
|
160
158
|
|
161
159
|
glDeleteTextures(1, &textureID);
|
162
160
|
|