Индексы кажутся правильными. Даны 30 точек вокруг каждой строки:
0, 30, 1, 31, 2, 32, ... 29, 59, 0, 30
Затем в конце каждой строки есть вырожденные треугольники.
Насколько я подсчитал, если вокруг каждого круга вокруг планеты на линии широты есть точки lonRes (в демо, lonRes= 30) тогда должно быть lonRes+4 в каждой строке, потому что есть две точки, соединяющиеся с началом, а затем две вырожденные точки для следующей строки. Каким-то образом это вычисление отключено, indexSize = 2503, а фактический размер - 2432.
Вращение, кажется, работает, но на краю каждой строки есть черный зазор, показывающий какую-то ошибку текстуры, и, что еще более странно, он вращается назад. .
Я прилагаю код, шейдеры, хотя я вполне уверен, что проблема не в них, а также скриншот, показывающий ошибку.
Код: Выделить всё
/*
Textured Sphere demo
Load a webp cylindrical projection of earth and map to the sphere
Tilt earth axis to 23.5 degrees and rotate
*/
#include
#include "common/common.hh"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace glm;
using namespace std::numbers;
constexpr double PI = numbers::pi;
class Sphere {
private:
uint32_t progid; // handle to the shader code
uint32_t vao; // array object container for vbo and indices
uint32_t vbo; // handle to the point data on the graphics card
uint32_t lbo; // handle to buffer of indices for lines for wireframe sphere
uint32_t latRes, lonRes;
uint32_t resolution;
uint32_t indexSize;
public:
/**
* @brief Construct a sphere
*
* @param r radius of the sphere
* @param latRes resolution of the grid in latitude
* @param lonRes resolution of the grid in latitude
* @param texturePath path to the texture image
*/
Sphere(double r, uint32_t latRes, uint32_t lonRes);
~Sphere() { cleanup(); }
void render(mat4& trans, GLuint textureID);
void cleanup();
};
Sphere::Sphere(double r, uint32_t latRes, uint32_t lonRes) : latRes(latRes), lonRes(lonRes),
resolution((2*latRes-1)*lonRes + 2) {
progid = loadShaders("06b_texturepoints.vert", "06b_textures.frag");
// progid = loadShaders("03gouraud.vert", "03gouraud.frag");
double dlon = 2.0*PI / lonRes, dlat = PI / (2*latRes);
double z;
double lat = -PI/2 + dlat; // latitude in radians
double rcircle;
float vert[resolution*5]; // x,y,z,u,v
uint32_t c = 0;
for (uint32_t j = 0; j < 2*latRes-1; j++, lat += dlat) {
//what is the radius of hte circle at that height?
rcircle = r* cos(lat); // size of the circle at this latitude
z = r * sin(lat); // height of each circle
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79372704/rendering-a-spinning-globe-appears-to-work-but-at-the-end-of-each-row-it-appear[/url]