游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3104|回复: 6

opengl难题!!!

[复制链接]

2

主题

6

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2004-6-6 10:46:00 | 显示全部楼层 |阅读模式
在vc环境下用opengl编写了一个动画,但是场景中的所有物体都不显示,运行完后出现的画面是黑屏,不只是什么原因?请高手指教!!在线等待!!

45

主题

286

帖子

314

积分

中级会员

自由游戏制作人

Rank: 3Rank: 3

积分
314
QQ
发表于 2004-6-6 10:54:00 | 显示全部楼层

Re:opengl难题!!!

汗,不发代码,或者调试信息,我想没有人能正确回答你

62

主题

331

帖子

366

积分

中级会员

Rank: 3Rank: 3

积分
366
QQ
发表于 2004-6-6 11:17:00 | 显示全部楼层

Re:opengl难题!!!

或者
显示器坏了?

..

2

主题

6

帖子

12

积分

新手上路

Rank: 1

积分
12
 楼主| 发表于 2004-6-6 14:27:00 | 显示全部楼层

Re: opengl难题!!!

以下是源代码,请各位多多帮忙!!
其实该程序的效果是一个旋转的正方体每个面上都有同样的一个位图图片!!图片也附上!
// 11.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>                // Header File For Windows
#include <stdio.h>
#include <stdlib.h>                        // Header File For Standard Input/Output
#include <gl\gl.h>                        // Header File For The OpenGL32 Library
#include <gl\glu.h>                        // Header File For The GLu32 Library
#include <gl\glaux.h>
#include <GL/glut.h>

GLfloat        xrot;                                // X Rotation ( NEW )
GLfloat        yrot;                                // Y Rotation ( NEW )
GLfloat        zrot;                                // Z Rotation ( NEW )

GLuint        texture[1];                        // Storage For One Texture ( NEW )


AUX_RGBImageRec *LoadBMP(char *Filename)                                // Loads A Bitmap Image
{
        FILE *File=NULL;                                                                        // File Handle

        if (!Filename)                                                                                // Make Sure A Filename Was Given
        {
                return NULL;                                                                        // If Not Return NULL
        }

        File=fopen(Filename,"r");                                                        // Check To See If The File Exists

        if (File)                                                                                        // Does The File Exist?
        {
                fclose(File);                                                                        // Close The Handle
                return auxDIBImageLoad(Filename);                                // Load The Bitmap And Return A Pointer
        }

        return NULL;                                                                                // If Load Failed Return NULL
}

int LoadGLTextures()                                                                        // Load Bitmaps And Convert To Textures
{
        int Status=FALSE;                                                                        // Status Indicator

        AUX_RGBImageRec *TextureImage[1];                                        // Create Storage Space For The Texture

        memset(TextureImage,0,sizeof(void *)*1);                   // Set The Pointer To NULL

        // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
        if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
        {
                Status=TRUE;                                                                        // Set The Status To TRUE

                glGenTextures(1, &texture[0]);                                        // Create The Texture

                // Typical Texture Generation Using Data From The Bitmap
                glBindTexture(GL_TEXTURE_2D, texture[0]);
                glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        }

        if (TextureImage[0])                                                                        // If Texture Exists
        {
                if (TextureImage[0]->data)                                                        // If Texture Image Exists
                {
                        free(TextureImage[0]->data);                                        // Free The Texture Image Memory
                }

                free(TextureImage[0]);                                                                // Free The Image Structure
        }

        return Status;                                                                                // Return The Status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)                // Resize And Initialize The GL Window
{
        if (height==0)                                                                                // Prevent A Divide By Zero By
        {
                height=1;                                                                                // Making Height Equal One
        }

        glViewport(0,0,width,height);                                                // Reset The Current Viewport

        glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
        glLoadIdentity();                                                                        // Reset The Projection Matrix

        // Calculate The Aspect Ratio Of The Window
        gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

        glMatrixMode(GL_MODELVIEW);                                                        // Select The Modelview Matrix
        glLoadIdentity();                                                                        // Reset The Modelview Matrix
}

void InitGL(GLvoid)                                                                                // All Setup For OpenGL Goes Here
{


        glEnable(GL_TEXTURE_2D);                                                        // Enable Texture Mapping ( NEW )
        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
                                                                                        // Initialization Went OK
}

void display()                                                                        // Here's Where We Do All The Drawing
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear The Screen And The Depth Buffer
        glLoadIdentity();                                                                        // Reset The View
        glTranslatef(0.0f,0.0f,-5.0f);

        glRotatef(xrot,1.0f,0.0f,0.0f);
        glRotatef(yrot,0.0f,1.0f,0.0f);
        glRotatef(zrot,0.0f,0.0f,1.0f);

        glBindTexture(GL_TEXTURE_2D, texture[0]);

        glBegin(GL_QUADS);
                // Front Face
                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);
                // Back Face
                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);
                // Top Face
                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);
                // Bottom Face
                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);
                // Right face
                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);
                // Left Face
                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();

        xrot+=0.3f;
        yrot+=0.2f;
        zrot+=0.4f;
                                                                                // Keep Going
}



int main(int argc, char* argv[])
{
        glutInitDisplayMode( GLUT_RGB );
        glutInitWindowPosition(200, 0);
    glutInit(&argc, argv);
        glutInitWindowSize(640, 480);
           glutCreateWindow("星连星愿");
        InitGL();
        glutDisplayFunc(display);
//        glutKeyboardFunc(parsekey);
//        glutSpecialFunc(parsekey_special);
        glutReshapeFunc(ReSizeGLScene);
        glutMainLoop();
       
        return 0;
}
sf_200466142753.bmp

55

主题

175

帖子

193

积分

注册会员

Rank: 2

积分
193
发表于 2004-6-7 10:24:00 | 显示全部楼层

Re:opengl难题!!!

1.display()最后没有glFlush()
2.没有调用LoadTexture

2

主题

6

帖子

12

积分

新手上路

Rank: 1

积分
12
 楼主| 发表于 2004-6-7 20:36:00 | 显示全部楼层

Re:opengl难题!!!

谢谢l楼上朋友的回贴,不过我按照你说的修改了还是不成功!但是又出现了两个错误,本来编译是没有错误的
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/12.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
能不能帮我将程序调试修改一下!非常感谢!!!

0

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2004-6-19 14:11:00 | 显示全部楼层

Re:opengl难题!!!

在#include"..."下面加入
#pragma comment(lib,"glaux.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
void InitGL(GLvoid){
...
LoadGLTextures();
}
void display() // Here's Where We Do All The Drawing
{
...
glFlush();
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-2 06:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表