大家看看我的程序为什么不能绘制出图来,我想点一下鼠标就在鼠标的位置画个圆
#include<GL/glut.h>#include<stdio.h>#include<math.h>#include<stdlib.h>#include<Window...
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <Windows.h>
float mousex=0,mousey=0;
void init (void)
{
glClearColor (0.0,0.0,0.0,0.0);
gluOrtho2D (0.0,400.0,0.0,300.0);
}
void reshape(int w, int h)
{
glViewport(0, 0,(GLsizei) w, (GLsizei) h);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT) ;
glColor3f(1.0, 0.0, 0.0) ;
glFlush() ;
}
void redisplay(void)
{
int xd=0,yd=0,r=40,x,y,xb,yb,xf,yf,d,x1b,y1b,x1f,y1f;
glTranslatef(mousex,mousey,0);
x=0;
y=r;
d=1-r;
glBegin(GL_POINTS);
while(x<y)
{
if(d<0)
d+=2*x+3;
else
{
d+=2*(x-y)+5;
y--;}
xb=x+xd;//x、y不交换
yb=y+yd;
xf=xd-x;
yf=yd-y;
x1b=y+xd;//交换x、y的处理
y1b=x+yd;
x1f=xd-y;
y1f=yd-x;
glVertex2i(xb, yb);
glVertex2i(xf, yb);
glVertex2i(xb, yf);
glVertex2i(xf, yf);
glVertex2i(x1b, y1b);
glVertex2i(x1f, y1b);
glVertex2i(x1b, y1f);
glVertex2i(x1f, y1f);
x++;}
glEnd();
glFlush() ; }
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
{
mousex=x;
mousey=800-y;
redisplay();
}
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv) ;
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) ;
glutInitWindowSize(400, 300) ;
glutCreateWindow("tjf06") ;
glutFullScreen();
init() ;
glutMouseFunc(mouse);
glutReshapeFunc(reshape);
glutDisplayFunc(display) ;
glutKeyboardFunc(keyboard);
glutMainLoop() ;
return 0 ;
}
opengl中glTranslatef函数是不是不能用变量作参数啊 ,为什么我一把mousex和mousey两个变量作为他的参数就不能绘出图来,直接用数字就可以? 展开
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <Windows.h>
float mousex=0,mousey=0;
void init (void)
{
glClearColor (0.0,0.0,0.0,0.0);
gluOrtho2D (0.0,400.0,0.0,300.0);
}
void reshape(int w, int h)
{
glViewport(0, 0,(GLsizei) w, (GLsizei) h);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT) ;
glColor3f(1.0, 0.0, 0.0) ;
glFlush() ;
}
void redisplay(void)
{
int xd=0,yd=0,r=40,x,y,xb,yb,xf,yf,d,x1b,y1b,x1f,y1f;
glTranslatef(mousex,mousey,0);
x=0;
y=r;
d=1-r;
glBegin(GL_POINTS);
while(x<y)
{
if(d<0)
d+=2*x+3;
else
{
d+=2*(x-y)+5;
y--;}
xb=x+xd;//x、y不交换
yb=y+yd;
xf=xd-x;
yf=yd-y;
x1b=y+xd;//交换x、y的处理
y1b=x+yd;
x1f=xd-y;
y1f=yd-x;
glVertex2i(xb, yb);
glVertex2i(xf, yb);
glVertex2i(xb, yf);
glVertex2i(xf, yf);
glVertex2i(x1b, y1b);
glVertex2i(x1f, y1b);
glVertex2i(x1b, y1f);
glVertex2i(x1f, y1f);
x++;}
glEnd();
glFlush() ; }
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
{
mousex=x;
mousey=800-y;
redisplay();
}
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv) ;
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) ;
glutInitWindowSize(400, 300) ;
glutCreateWindow("tjf06") ;
glutFullScreen();
init() ;
glutMouseFunc(mouse);
glutReshapeFunc(reshape);
glutDisplayFunc(display) ;
glutKeyboardFunc(keyboard);
glutMainLoop() ;
return 0 ;
}
opengl中glTranslatef函数是不是不能用变量作参数啊 ,为什么我一把mousex和mousey两个变量作为他的参数就不能绘出图来,直接用数字就可以? 展开
1个回答
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询