PC에서이 코드를 실행하고 있습니다 (코드 : blocks 10.05로 컴파일 됨)
GLUT (GL Utiltiy Toolkit)로 기본 OpenGL 코드를 사용하는 경우 모두 정상적으로 작동합니다.
번역 기능의 z 축 (세 번째 매개 변수)을 기하학적 기본 (쿼드)의 위치로 변경하려고 할 때 SDL 프레임 워크를 통해 OpenGL 코드를 실행 중입니다. 3D 공간에는 깊이가없는 것으로 나타나고 전체 화면을 보여 주거나 깊이가 특정 지점에 도달하면 완전히 사라집니다.
누락 된 항목이 있습니까? :/SDL OpenGL 코드가 보이지 않는 경우
#include <sdl.h>
#include <string>
#include "sdl_image.h"
#include "SDL/SDL_opengl.h"
#include <gl\gl.h>
// Declare Constants
const int FRAMES_PER_SECOND = 60;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
// Create Event Listener
SDL_Event event;
// Declare Variable Used To Control How Deep Into The Screen The Quad Is
GLfloat zpos(0);
// Loop Switches
bool gamestarted(false);
bool exited(false);
// Prototype For My GL Draw Function
void drawstuff();
// Code Begins
void init_GL() {
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glViewport(0, 0, 640, 513); // Viewport Change
glOrtho(0, 640, 0, 513, -1.0, 1.0); // Puts Stuff Into View
}
bool init() {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640, 513, 32, SDL_OPENGL);
return true;
}
void drawstuff() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, zpos);
glColor3f(0.5f,0.5f,0.5f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
}
int main (int argc, char* args[]) {
init();
init_GL();
while(exited == false) {
while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) {
exited = true;
}
if(event.type == SDL_MOUSEBUTTONDOWN) {
zpos-=.1;
}
}
glClear(GL_COLOR_BUFFER_BIT);
drawstuff();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}
나는 그것을 시도하고 그것이 작동하지 않았다. 내가 놓친 게 있니? 그나 저의 도움에 감사드립니다 !! 지금까지 glOrtho 호출 줄 삭제 시도하고 "gluPerspective (45.0f, (GLfloat) 640/(GLfloat) 513,0.1f, 100.0f);" – agusterodin
신경이 쓰이지 않으면 신경 쓰지 않아도됩니다. (위의 주석에서 볼 수 있듯이) 원근법으로 변경하고 .1 대신 1 씩 변수를 줄이면 효과가 있음을 알 수 있습니다. 감사합니다 – agusterodin