I changed my code a little, but still getting the annoying errors. Perhaps someone can still help me out?
#include <vector>
#include <math.h>
#include <GL/glut.h>
#include <thrust\host_vector.h>
#include <thrust\device_vector.h>
#include <cuda.h>
#include <device_launch_parameters.h>
#include <cuda_gl_interop.h>
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
int const win_width = 512;
int const win_height = 512;
// using namespace std;
class SolidSphere
{
protected:
thrust::host_vector<GLfloat> vertices;
thrust::host_vector<GLfloat> normals;
thrust::host_vector<GLfloat> texcoords;
thrust::host_vector<GLushort> indices;
public:
__device__ __host__ SolidSphere(float radius, unsigned int rings,
unsigned int sectors)
{
float const R = 1./(float)(rings-1);
float const S = 1./(float)(sectors-1);
int r, s;
vertices.resize(rings * sectors * 3);
normals.resize(rings * sectors * 3);
texcoords.resize(rings * sectors * 2);
thrust::host_vector<GLfloat>::iterator v = vertices.begin();
thrust::host_vector<GLfloat>::iterator n = normals.begin();
thrust::host_vector<GLfloat>::iterator t = texcoords.begin();
for(r = 0; r < rings; r++) {
for(s = 0; s < sectors; s++) {
float const y = sin(-M_PI_2 + M_PI * r * R);
float const x = cos(2*M_PI * s * S) * sin(M_PI * r * R);
float const z = sin(2*M_PI * s * S) * sin(M_PI * r * R);
*t++ = s*S;
*t++ = r*R;
*v++ = x * radius;
*v++ = y * radius;
*v++ = z * radius;
*n++ = x;
*n++ = y;
*n++ = z;
}
}
indices.resize(rings * sectors * 4);
thrust::host_vector<GLushort>::iterator i = indices.begin();
for (r = 0; r < rings-1; r++) {
for(s = 0; s < sectors-1; s++) {
*i++ = r * sectors + s;
*i++ = r * sectors + (s+1);
*i++ = (r+1) * sectors + (s+1);
*i++ = (r+1) * sectors + s;
}
}
}
void draw(float x, float y, float z)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(x, y, z);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
glNormalPointer(GL_FLOAT, 0, &normals[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &texcoords[0]);
glDrawElements(GL_QUADS, indices.size(), GL_UNSIGNED_SHORT, &indices);
glPopMatrix();
}
};
SolidSphere sphere(1, 12, 24);
void initGL() {
struct Light {
float ambient[4];
float diffuse[4];
float specular[4];
float position[4];
} light = {
{ 0.2, 0.2, 0.2, 1.0 },
{ 0.8, 0.8, 0.8, 1.0 },
{ 1.0, 1.0, 1.0, 1.0 },
{ 1.0, 1.0, 1.0, 0.0 }
};
struct Material {
float ambient[4];
float diffuse[4];
float specular[4];
float shininess[1];
} material = {
{ 0.8, 0.8, 0.8, 1.0 },
{ 0.8, 0.8, 0.8, 1.0 },
{ 1.0, 1.0, 1.0, 1.0 },
{ 96 }
};
glClearColor(0.5, 0.5, 1.0, 1.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light.position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light.ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light.diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light.specular);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
}
}
void display()
{
float const win_aspect = (float)win_width/(float)win_height;
glViewport(0, 0, win_width, win_height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.6, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, win_aspect, 0.25, 200);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#ifdef DRAW_WIREFRAME
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif
sphere.draw(0, 0, -5);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(win_width, win_height);
glutInitWindowPosition(100, 100);
glutCreateWindow("3D Sphere");
initGL();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<unsigned short, std::allocator<unsigned short> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(34): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(35): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(36): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(38) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(39) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(40) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(61): warning : calling a __host__ function("thrust::detail::vector_base<unsigned short, std::allocator<unsigned short> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(62) (col. 43) : warning : calling a __host__ function("thrust::detail::vector_base<unsigned short, std::allocator<unsigned short> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<float, std::allocator<float> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(29): warning : calling a __host__ function("thrust::host_vector<unsigned short, std::allocator<unsigned short> > ::host_vector") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(34): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(35): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(36): warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(38) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(39) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(40) (col. 42) : warning : calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(61): warning : calling a __host__ function("thrust::detail::vector_base<unsigned short, std::allocator<unsigned short> > ::resize") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed
1>
1>C:/Users/Baba Vida/Documents/Visual Studio 2010/Projects/mycudainterop1/mycudainterop1.cu(62) (col. 43) : warning : calling a __host__ function("thrust::detail::vector_base<unsigned short, std::allocator<unsigned short> > ::begin") from a __host__ __device__ function("SolidSphere::SolidSphere") is not allowed