Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用opengl c++;_C++_Opengl_Skybox - Fatal编程技术网

C++ 使用opengl c++;

C++ 使用opengl c++;,c++,opengl,skybox,C++,Opengl,Skybox,我正试图用skybox创建我的太阳系的背景;然而,它并没有输出我所认为的结果 首先是显示问题。下面的图片显示了我遇到的问题。 不同角度: 另一个角度: 如您所见,纹理仅映射到立方体的一侧。如果它被映射到的一侧是内部一侧,那就可以了。我不明白为什么它没有被正确地映射 第二个问题是(正如你从图片中看到的)当我旋转相机时,盒子也随之旋转,当我缩小时,我可以看到整个盒子。我希望这个盒子永远留在背景中,并且只能放大/缩小我的太阳系。这样,星星总是在背景中。我不知道如何完成它 这是我用来渲染天空盒和太

我正试图用skybox创建我的太阳系的背景;然而,它并没有输出我所认为的结果

首先是显示问题。下面的图片显示了我遇到的问题。

不同角度:

另一个角度:

如您所见,纹理仅映射到立方体的一侧。如果它被映射到的一侧是内部一侧,那就可以了。我不明白为什么它没有被正确地映射

第二个问题是(正如你从图片中看到的)当我旋转相机时,盒子也随之旋转,当我缩小时,我可以看到整个盒子。我希望这个盒子永远留在背景中,并且只能放大/缩小我的太阳系。这样,星星总是在背景中。我不知道如何完成它

这是我用来渲染天空盒和太阳系的代码。(请记住,太阳系是按我预期的方式运行的)

这是skybox的代码:

void Skybox::displaySkybox() 
{

    Images::RGBImage test[6]; //6 pictures for 6 sides
    test[0]=Images::readImageFile(fileName); //I'll only use one for testing purposes
    glEnable(GL_TEXTURE_2D);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    test[0].glTexImage2D(GL_TEXTURE_2D,0,GL_RGB);

    // Save Current Matrix
    glPushMatrix();

    // Second Move the render space to the correct position (Translate)
    glTranslatef(0,0,0);

    // First apply scale matrix
    glScalef(10000,10000,10000);

    float cz = -0.0f,cx = 1.0f;
    float r = 1.0f; // If you have border issues change this to 1.005f
    // Common Axis Z - FRONT Side

    glBegin(GL_QUADS);  
        glTexCoord2f(cx, cz); glVertex3f(-r,1.0f,-r);
        glTexCoord2f(cx, cx); glVertex3f(-r,1.0f, r);
        glTexCoord2f(cz, cx); glVertex3f( r,1.0f, r); 
        glTexCoord2f(cz, cz); glVertex3f( r,1.0f,-r);
    glEnd();

    // Common Axis Z - BACK side

    glBegin(GL_QUADS);      
        glTexCoord2f(cx,cz);  glVertex3f(-r,-1.0f,-r);
        glTexCoord2f(cx,cx);  glVertex3f(-r,-1.0f, r);
        glTexCoord2f(cz,cx);  glVertex3f( r,-1.0f, r); 
        glTexCoord2f(cz,cz);  glVertex3f( r,-1.0f,-r);
    glEnd();

// Common Axis X - Left side

glBegin(GL_QUADS);      
    glTexCoord2f(cx,cx); glVertex3f(-1.0f, -r, r);  
    glTexCoord2f(cz,cx); glVertex3f(-1.0f,  r, r); 
    glTexCoord2f(cz,cz); glVertex3f(-1.0f,  r,-r);
    glTexCoord2f(cx,cz); glVertex3f(-1.0f, -r,-r);      
glEnd();

// Common Axis X - Right side

glBegin(GL_QUADS);      
    glTexCoord2f(cx, cx); glVertex3f(1.0f, -r, r);  
    glTexCoord2f(cz, cx); glVertex3f(1.0f,  r, r); 
    glTexCoord2f(cz, cz); glVertex3f(1.0f,  r,-r);
    glTexCoord2f(cx, cz); glVertex3f(1.0f, -r,-r);
glEnd();

// Common Axis Y - Draw Up side

glBegin(GL_QUADS);      
    glTexCoord2f(cz, cz); glVertex3f( r, -r, 1.0f);
    glTexCoord2f(cx, cz); glVertex3f( r,  r, 1.0f);
    glTexCoord2f(cx, cx); glVertex3f(-r,  r, 1.0f);
    glTexCoord2f(cz, cx); glVertex3f(-r, -r, 1.0f);
glEnd();

// Common Axis Y - Down side

glBegin(GL_QUADS);      
    glTexCoord2f(cz, cz); glVertex3f( r, -r, -1.0f);
    glTexCoord2f(cx, cz); glVertex3f( r,  r, -1.0f);
    glTexCoord2f(cx, cx); glVertex3f(-r,  r, -1.0f);
    glTexCoord2f(cz, cx); glVertex3f(-r, -r, -1.0f);
glEnd();

// Load Saved Matrix
glPopMatrix();


}
以下是太阳系的代码:

void SolarSystem::display(GLContextData& contextData) const
{   

glDisable(GL_LIGHTING);
Skybox test("images/test.jpg");
test.displaySkybox();

drawCircle(800, 720, 2, 100);
//SUN
        //Picture location, major radius, minor radius, major orbit, minor orbit, angle
Planet Sun ("images/Sun.jpg", 
                 100, 99, 200.0, 0.0, 0.0);
double sunOrbS = 0;
double sunRotS = rotatSpeed/10;

//orbit speed, rotation speed, moon reference coordinates (Parent planet's major and minor Axis)
Sun.displayPlanet(sunOrbS, sunRotS, 0.0, 0.0);


//EARTH

GLfloat light_diffuse[] = { 1.5, 1.5, 1.5, 1.5 };
GLfloat pos[] = { 200.0, 0.0, 0.0, 1.0};
glEnable(GL_LIGHTING);  
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, pos);


Planet Earth ("images/earth.jpg", 
           50, 49, 500.0, 450.0, 23.5);
double eaOrbS = orbitSpeed;
double eaRotS = rotatSpeed*3;

Earth.displayPlanet(eaOrbS, eaRotS, 0.0, 0.0);


//EARTH'S MOON
Planet Moon ("images/moon.jpg", 
           25, 23, 100.0, 100.0, 15);
double moOrbS = rotatSpeed*4;
double moRotS = eaOrbS;

Moon.displayPlanet(moOrbS, moRotS, Earth.getMajorAxis(), Earth.getMinorAxis());

orbitSpeed+=.3;
if (orbitSpeed > 359.0)
orbitSpeed = 0.0;


rotatSpeed+=1.0;
if (rotatSpeed > 7190.0)
rotatSpeed = 0.0;


}

不要那样做。确保你按
Pop
的次数和你按
Pop的次数一样多

我把它修好了。我在两个
推送之间尝试了一些东西,但它不起作用,所以我删除了它,忘了删除那一个。谢谢你抓住它。这解决了
堆栈溢出问题。一旦一切正常,您可能不希望翻译影响skybox。只有旋转。在空中盒子里移动太多会让事情看起来很奇怪。
void Skybox::displaySkybox() 
{
    ...
    glPushMatrix();
    ...
    glPushMatrix();
    ...
    glPopMatrix();
    ...
    // huh?  where's the second glPopMatrix()?
}