求助:linux下根据坐标点画 .png格式图片
各位精通linux下编程的大牛们新年好!
我现在碰到一个自己之前没怎么接触过的内容,所以向各位大牛求助。比如:有一些坐标点数据,需要在linux下根据这些坐标点,画出 .png 格式的图片。在网上查过一些资料,比如用libpng, 试了一天,没成功。
敬请有丰富经验的大牛多多指教!感谢!
[解决办法]
用QT之类的呗。
[解决办法]
使用glut,基于opengl,但是需要你自己下载所需要的库文件。
贴出一段代码于你尝试文件名为test.cpp:
代码中是个例子,若要尝试画png图片,建议先看看opengl方面的书籍。
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
int central_orbit_period = 0;
int planet_rotation_period = 0;
int satellite_rotation_period = 0;
void init(void)
{
glClearColor(0.1, 0.1, 0.1, 0.0);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// push matrix, draw central planet, then pop matrix:
glPushMatrix();
{
glRotatef((GLfloat)planet_rotation_period, 0.0, 1.0, 0.0);
glColor4f(1.0, 0.0, 0.0, 1.0);
glutSolidSphere(1.0, 10, 8); // Draw the central planet
} glPopMatrix();
// push matrix, draw satellite, then pop matrix:
glPushMatrix();
{
glRotatef((GLfloat)central_orbit_period, 0.0, 1.0, 0.0);
glTranslatef(1.9, 0.0, 0.0);
glRotatef((GLfloat)-satellite_rotation_period, 0.0, 1.0, 0.0);
glColor4f(0.0, 1.0, 0.0, 1.0);
glutSolidSphere(0.2, 5, 4); // Draw the orbiting satellite
} glPopMatrix();
glutSwapBuffers();
central_orbit_period = (central_orbit_period + 2) % 360;
planet_rotation_period = (planet_rotation_period + 1) % 360;
satellite_rotation_period = (satellite_rotation_period + 6) % 360;
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void cycle_view() {
static int count = 0;
static int shade_flag = 0;
if (++count > 2) {
count = 0;
shade_flag = 1 - shade_flag;
}
glLoadIdentity();
switch (count)
{
case 0:
gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
break;
case 1:
gluLookAt(0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
break;
case 2:
gluLookAt(0.0, 0.5, -3.3, 1.0, 0.0, 0.0, -0.7, 0.2, 0.4);
break;
}
if (shade_flag == 0) glShadeModel(GL_SMOOTH);
else glShadeModel(GL_FLAT);
}
void key_press_callback(unsigned char key, int x, int y) {
switch (key)
{
case 27: /* escape character */
case 'q':
case 'Q':
exit(1);
default:
cycle_view();
break;
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutKeyboardFunc(key_press_callback);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
编译方法:
g++ -lGL -lGLU -lglut -o test.o test.cpp
------解决方案--------------------
你用的啥编程环境开发的?