这程序在终端和用gdb调试的时候给出的信息不一样阿

yueyuezai 2008-12-07 07:38:41
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <iostream>
#include "stack.h"

#define FILL_COLOR 100
#define BORDER_COLOR 255

using namespace std;
void DrawRegion();
void myInit(void);
void myDisplay(void);
void RegionFill(void);

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("my first attempt");
myInit();
glutDisplayFunc(myDisplay);
//glutReshapeFunc(myReshape);
//glutMouseFunc(myMouse);
//glutKeyboardFunc(myKeyboard);

glutMainLoop();

return 0;
}
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glPointSize(1.0);//设置点的大小为一个像素
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
DrawRegion();
RegionFill();
glFlush();
}
void RegionFill(void)
{
Point seed = {300, 180};
Stack stack;
stack.Push(seed);
glColor3ub(100, 0, 0);
while(!stack.IsEmpty())
{
Point point;
stack.Pop(point);
glBegin(GL_POINTS);
glVertex2i(point.x, point.y);
glEnd();
GLint xi = point.x + 1;
GLubyte iPixel = 0;
glReadPixels(xi, point.y, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);//读取一点的红色通道值
int ret = glGetError();
cerr << int(iPixel) <<" " << ret;
while(iPixel != BORDER_COLOR)//向右填充
{
glBegin(GL_POINTS);
glVertex2i(xi, point.y);
glEnd();
xi++;
glReadPixels(xi, point.y, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
}
cerr << xi;
GLint xRight = xi--;//记录最右点
xi = point.x - 1;
glReadPixels(xi, point.y, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
while(int(iPixel) != BORDER_COLOR)
{
glBegin(GL_POINTS);
glVertex2i(xi, point.y);
glEnd();
xi--;
glReadPixels(xi, point.y, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
}
//GLint xLeft = xi++;//记录最左点
for(int i = -1; i <= 1; i += 2)
{
while(xi <= xRight)
{
glReadPixels(xi, point.y + i, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
while(iPixel != BORDER_COLOR && iPixel != FILL_COLOR && xi <= xRight)
{
xi++;
glReadPixels(xi, point.y + i, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
}
Point tmpPoint = {xi - 1, point.y + i};
stack.Push(tmpPoint);
while(iPixel == BORDER_COLOR || iPixel == FILL_COLOR && xi <= xRight)
{
xi++;
glReadPixels(xi, point.y + i, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &iPixel);
}
}
}
}
}
void DrawRegion(void)
{
glColor3ub(0, 0, 0);
glBegin(GL_LINES);
glVertex2i(50, 50);
glVertex2i(180, 300);
glVertex2i(180, 300);
glVertex2i(300, 200);
glVertex2i(300, 200);
glVertex2i(450, 320);
glVertex2i(450, 320);
glVertex2i(350, 80);
glVertex2i(350, 80);
glVertex2i(250, 150);
glVertex2i(250, 150);
glVertex2i(150, 150);
glVertex2i(150, 150);
glVertex2i(50, 50);
glEnd();
glFlush();
GLubyte Pixel;
glReadPixels(50, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &Pixel);
cerr << int(Pixel)<< " ";
}
输出的结果终端的时候是0 118 0,gdb的时候255 0 0
还都是感觉不正确的
...全文
67 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnsls33 2008-12-07
  • 打赏
  • 举报
回复
mark
qap22 2008-12-07
  • 打赏
  • 举报
回复
mark
yueyuezai 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ilovedrv 的回复:]
终端输出的应该是正确的,你的gdb是不是查看的地址不正确
[/Quote]
主要是这两个结果都不是正确的结果,会不会read读取的像素不对?读的buffer不对?
gdb查看什么地址呢,我只是运行了run然后输出的是是我程序中cerr的结果阿
ilovedrv 2008-12-07
  • 打赏
  • 举报
回复
终端输出的应该是正确的,你的gdb是不是查看的地址不正确

19,464

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧