openGL窗口一切换就没有了

#include<gl/glut.h>voidmyDisplay(){glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_SMOOT... #include <gl/glut.h>
void myDisplay()
{
glClear( GL_COLOR_BUFFER_BIT );
glShadeModel( GL_SMOOTH );
glMatrixMode(GL_PROJECTION);
gluOrtho2D(-300,300,0,300);

glMatrixMode(GL_MODELVIEW);
//现在原点绘制一个蓝色长方形
glColor3f( 0.0, 0.0, 1.0 );
glRectf(50,100, 200,150);

glFlush();

}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 250);
glutCreateWindow("第一个OpenGL程序");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
展开
 我来答
阿金纪实录
2013-08-16 · TA获得超过766个赞
知道小有建树答主
回答量:250
采纳率:100%
帮助的人:129万
展开全部

#include <windows.h>
#include <gl/glut.h>
#include <GL/gl.h>
void initGL(void);
void resizeWidget(int w,int h)
{
    if(0==h)
        h=1;
    //GLfloat aspect=(GLfloat)w/(GLfloat)h;
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0,w,0,h);
    glMatrixMode(GL_MODELVIEW);
}

void myDisplay()
{
        initGL();
        glClear( GL_COLOR_BUFFER_BIT );
        glShadeModel( GL_SMOOTH );
        //glMatrixMode(GL_PROJECTION);
        //gluOrtho2D(-300,300,0,300);

        //glMatrixMode(GL_MODELVIEW);
        //现在原点绘制一个蓝色长方形
        glColor3f( 0.0, 0.0, 1.0 );
        glRectf(50,100, 200,150);

glFlush();

}
void initGL(void)
{
    glClearColor(0,0,0,1);
}

int main(int argc, char *argv[])
{
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
        glutInitWindowPosition(100, 100);
        glutInitWindowSize(500, 250);
        glutCreateWindow("第一个OpenGL程序");
        glutDisplayFunc(&myDisplay);
        glutReshapeFunc(resizeWidget);
        glutMainLoop();
        return 0;
}
我在你的原头文件里加了两个头文件和另外加了连接库=-lopengl32 -lfreeglut -lglu32
就能够显示一个黑色的窗口可是不能显示蓝色的矩形,我已经改好了。

百度网友41e79cacc
2013-08-17 · TA获得超过204个赞
知道答主
回答量:104
采纳率:0%
帮助的人:37.1万
展开全部
很明显没有窗口重绘!glutReshapeFunc(reshape);

// BlueRect.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>
#include <WindowsX.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <GL/glut.h>

#include <stdlib.h>
#include <stdio.h>

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f( 0.0, 0.0, 1.0 );
glRectf(5,10, 20,15);

glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D(0.0, 30.0, 0.0, 30.0*(GLfloat) h/(GLfloat) w);
else
gluOrtho2D(0.0, 30.0*(GLfloat) w/(GLfloat) h, 0.0, 30.0);
glMatrixMode(GL_MODELVIEW);
}

int _tmain(int argc, _TCHAR* argv[])
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("This is the first OpenGL program!");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
治命延迟侠
2013-08-16 · 超过26用户采纳过TA的回答
知道答主
回答量:54
采纳率:0%
帮助的人:63.1万
展开全部
在调用glMatrixMode(GL_PROJECTION);之后要记得先调用下glLoadIdentity ();来初始化当前矩阵,否则当前矩阵会是个凌乱的矩阵
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式