gpt4 book ai didi

c++ - 潜在的错误 openGL

转载 作者:行者123 更新时间:2023-11-28 01:10:15 24 4
gpt4 key购买 nike

我正在尝试使用菜单在屏幕上平铺图像。我的菜单工作 - 以适当的方式平铺 - 直到我移动鼠标然后平铺设计消失?

#include <GL/glut.h>    
#include <fstream>
#include <cstdlib>
#include "TUGL.h"
#include <glui.h>

//Global variables

class GLintPoint
{
public:
GLint x;
GLint y;
};

GLint numpoints;
GLintPoint P[10];


window Win(800,600);
frame Frame;
GLUI *glui;
int mainwindow;

//Function prototypes

void readinpoints();
void drawline(GLint from, GLint to);
void display(void);
void init (void);
void keyboard(unsigned char key, int x, int y);
void tile1(void);
void tile4(void);
void tile9(void);
void tile16(void);
void myReshape(GLsizei W, GLsizei H);
void define_glui_window();
void choice_selected(int value);
void drawImage(void);
//Main

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (Win.width, Win.height);
glutInitWindowPosition (100, 100);
mainwindow = glutCreateWindow ("*star*");

init();
define_glui_window();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(myReshape);
readinpoints();

glutMainLoop();
return 0;
}

//Functions

void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0); //set background color
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 200, 0.0, 249, -1.0, 1.0);

}

void readinpoints()

{
ifstream infile("polyline.pts");

numpoints=0;
infile>>P[numpoints].x>>P[numpoints].y;
while (!infile.eof())
{
numpoints++;
infile>>P[numpoints].x>>P[numpoints].y;
}
numpoints=numpoints-1;
}

void drawline(GLint from, GLint to)

{
glBegin(GL_LINES);
{
glVertex2i(P[from].x, P[from].y);
glVertex2i(P[to].x, P[to].y);
}
glEnd();
}

void drawImage(void);
{
glClear (GL_COLOR_BUFFER_BIT)
glColor3f (1.0, 0.0, 1.0);
glLineWidth(3);

drawline(0,1);
drawline(1,2);
drawline(2,3);
drawline(3,4);
drawline(4,5);
drawline(5,6);
drawline(6,7);
drawline(7,8);
drawline(8,9);
drawline(9,0);

glFlush();

}

void display(void)

{
glClear (GL_COLOR_BUFFER_BIT);
//autoViewPort(Frame, Win);
drawImage();
}

void tile1(void)

{ glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 1; i++)
for(int j=0; j < 1; j++)
{
//autoViewPort(Frame, Win);
glViewport(i * 800, j * 600, 800, 600);
drawImage();
glFlush();
}
}
void tile4(void)

{ glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 2; i++)
for(int j=0; j < 2; j++)
{
// autoViewPort(400, 300);
glViewport(i * 400, j * 300, 400, 300);
drawImage();
glFlush();
}
}
void tile9(void)

{
glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 3; i++)
for(int j=0; j < 3; j++)
{
// autoViewPort(267, 200);
glViewport(i * 267, j * 200, 267, 200);
drawImage();
glFlush();
}
}
void tile16(void)
{
glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 4; i++)
for(int j=0; j < 4; j++)
{
// autoViewPort(200, 150);
glViewport(i * 200, j * 150, 200, 150);
drawImage();
glFlush();
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
case 'f':

tile4();
break;
case 'n':
tile9();
break;
case 's':
tile16();
break;
case 'o':
tile1();
break;
}
}
void myReshape(GLsizei W, GLsizei H)

{
Win.set(W,H);
autoViewPort(Frame, Win);
}

void choice_selected(int value)

{
switch (value)
{
case 1:
tile1();
break;
case 2:
tile4();
break;
case 3:
tile9();
break;
case 4:
tile16();
break;
}
}

void define_glui_window()
{
glui = GLUI_Master.create_glui("OPTIONS", 0, 560, 50);

GLUI_StaticText *message1 = glui->add_statictext(" BACKGROUND COLOR ");
glui->add_button("Tile-1", 1, choice_selected);
glui->add_button("Tile-4", 2, choice_selected);
glui->add_button("Tile-9", 3, choice_selected);
glui->add_button("Tile-16", 4, choice_selected);
glui->set_main_gfx_window(mainwindow);
GLUI_Master.sync_live_all();
}

最佳答案

在每次 OpenGL 调用后使用 glError() 检查错误。失败的点将返回错误。然后您还可以查找错误代码以获取有关出错原因的额外信息。

关于c++ - 潜在的错误 openGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3817258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com