gpt4 book ai didi

c++ - 从文件中读取绘图点然后缩放

转载 作者:行者123 更新时间:2023-11-28 07:39:22 24 4
gpt4 key购买 nike

<分区>

我正在尝试用 C++ 使用 OpenGL 编写一个程序,该程序从文件中读取数据并缩放然后绘制数据。

文件中的数据是这样设置的:

0.017453293\tab 2.01623406\par0.087266463\tab 2.056771249\par0.191986218\tab 2.045176705\par0.27925268\tab 1.971733548\par

with the \tab signifying the x-coordinate and \par signifying the y-coordinate.

The code that I have written doesn't seem to be working though.

    #include "stdafx.h"
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "glut.h"
#include <iostream>
#include <string>
#include <fstream>

int _tmain(int argc, char **argv) {
void myInit(void);
void myDisplay(void);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("CMPS389 HW2");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}

void myInit(void) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}

void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
std::string words = "";
float locX;
float locY;

std::ifstream fileN("curveData.txt");

while(fileN != NULL) {
fileN>>words;

if (words == "\par") {
fileN>>locX;
}
if (words == "\tab") {
fileN>>locY;
glBegin(GL_LINES);
glVertex2f(locX*300, locY*300);
glEnd();
}
glFlush();
}
}

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