add basic test texture
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
||||
#include "OpenGLWindow/ShapeData.h"
|
||||
#include "OpenGLWindow/GLInstancingRenderer.h"
|
||||
|
||||
#include "OpenGLWindow/OpenGLInclude.h"
|
||||
bool gAllowCpuOpenCL = false;
|
||||
|
||||
#include "stb_image/stb_image.h"
|
||||
GpuDemo::GpuDemo()
|
||||
:m_clData(0)
|
||||
{
|
||||
@@ -122,3 +122,10 @@ int GpuDemo::registerGraphicsSphereShape(const ConstructionInfo& ci, float radiu
|
||||
}
|
||||
return graphicsShapeIndex;
|
||||
}
|
||||
|
||||
|
||||
unsigned char* GpuDemo::loadImage(const char* fileName, int& width, int& height, int& n)
|
||||
{
|
||||
unsigned char *data = stbi_load(fileName, &width, &height, &n, 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ public:
|
||||
arraySizeZ(10),
|
||||
#else
|
||||
|
||||
arraySizeX(20),
|
||||
arraySizeY(20),
|
||||
arraySizeZ(20),
|
||||
arraySizeX(30),
|
||||
arraySizeY(30),
|
||||
arraySizeZ(30),
|
||||
#endif
|
||||
m_useConcaveMesh(false),
|
||||
gapX(16.3),
|
||||
@@ -77,6 +77,8 @@ public:
|
||||
|
||||
virtual void clientMoveAndDisplay()=0;
|
||||
|
||||
unsigned char* loadImage(const char* fileName, int& width, int& height, int& n);
|
||||
|
||||
int registerGraphicsSphereShape(const ConstructionInfo& ci, float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
||||
|
||||
struct GpuDemoInternalData* getInternalData();
|
||||
|
||||
@@ -89,15 +89,38 @@ int GpuBoxPlaneScene::createDynamicsObjects(const ConstructionInfo& ci)
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||
return createDynamicsObjects2(ci,cube_vertices,numVertices,cube_indices,numIndices);
|
||||
return createDynamicsObjects2(ci,cube_vertices_textured,numVertices,cube_indices,numIndices);
|
||||
}
|
||||
|
||||
|
||||
int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const float* vertices, int numVertices, const int* indices, int numIndices)
|
||||
{
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int textureIndex = -1;
|
||||
{
|
||||
int width,height,n;
|
||||
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&vertices[0],numVertices,indices,numIndices);
|
||||
const char* filename = "data/cube.png";
|
||||
const unsigned char* image=0;
|
||||
|
||||
const char* prefix[]={"./","../","../../","../../../","../../../../"};
|
||||
int numprefix = sizeof(prefix)/sizeof(const char*);
|
||||
|
||||
for (int i=0;!image && i<numprefix;i++)
|
||||
{
|
||||
char relativeFileName[1024];
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||
image = loadImage(relativeFileName,width,height,n);
|
||||
}
|
||||
|
||||
b3Assert(image);
|
||||
if (image)
|
||||
{
|
||||
textureIndex = ci.m_instancingRenderer->registerTexture(image,width,height);
|
||||
}
|
||||
}
|
||||
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&vertices[0],numVertices,indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
||||
int group=1;
|
||||
int mask=1;
|
||||
int index=0;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "Bullet3Collision/NarrowPhaseCollision/b3Config.h"
|
||||
#include "GpuSoftBodyDemoInternalData.h"
|
||||
#include "Bullet3Collision/BroadPhaseCollision/b3DynamicBvhBroadphase.h"
|
||||
#include "stb_image/stb_image.h"
|
||||
|
||||
|
||||
static b3KeyboardCallback oldCallback = 0;
|
||||
extern bool gReset;
|
||||
@@ -298,50 +298,6 @@ GpuSoftClothDemo::~GpuSoftClothDemo()
|
||||
}
|
||||
|
||||
|
||||
unsigned char* GpuSoftClothDemo::loadImage(const char* fileName, int& width, int& height, int& n)
|
||||
{
|
||||
unsigned char *data = stbi_load(fileName, &width, &height, &n, 0);
|
||||
if (data)
|
||||
{
|
||||
GLubyte* image=new GLubyte[512*256*4];
|
||||
for(int y=0;y<256;++y)
|
||||
{
|
||||
const int t=y>>4;
|
||||
GLubyte* pi=image+y*512*3;
|
||||
for(int x=0;x<512;++x)
|
||||
{
|
||||
const int s=x>>5;
|
||||
const GLubyte b=180;
|
||||
GLubyte c=b+((s+t&1)&1)*(255-b);
|
||||
pi[0]=pi[1]=pi[2]=c;pi+=3;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
for (int i=0;i<width;i++)
|
||||
{
|
||||
for (int j=0;j<height;j++)
|
||||
{
|
||||
int offsetx = (512-width)/2;
|
||||
int offsety = (256-height)/2;
|
||||
|
||||
GLubyte* pi=image+((j+offsety)*512+i+offsetx)*3;
|
||||
const GLubyte* src=data+(j*width+i)*4;
|
||||
pi[0] = src[0];
|
||||
pi[1] = src[1];
|
||||
pi[2] = src[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
width = 512;
|
||||
height = 256;
|
||||
return image;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
@@ -412,8 +368,7 @@ void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
||||
int textureIndex = -1;
|
||||
{
|
||||
int width,height,n;
|
||||
FILE* f = fopen("test.tst","wb");
|
||||
fclose(f);
|
||||
|
||||
const char* filename = "data/bullet_logo.png";
|
||||
const unsigned char* image=0;
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ class GpuSoftClothDemo : public GpuSoftBodyDemo
|
||||
GpuSoftClothDemo();
|
||||
virtual ~GpuSoftClothDemo();
|
||||
|
||||
unsigned char* loadImage(const char* fileName, int& width, int& height, int& n);
|
||||
|
||||
virtual void setupScene(const ConstructionInfo& ci);
|
||||
|
||||
|
||||
@@ -1563,8 +1563,8 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||
b3Assert(err==GL_NO_ERROR);
|
||||
} else
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
|
||||
}
|
||||
static b3Vector3 lightPos = b3MakeVector3(-5.f,200,-40);//20,15,10);//-13,6,2);// = b3Vector3(0.5f,2,2);
|
||||
|
||||
@@ -161,6 +161,41 @@ static const float cube_vertices[] =
|
||||
1.0f,1.0f, -1.0f, 1.0f, 0,1,0, 0,1,
|
||||
};
|
||||
|
||||
///position xyz, unused w, normal, uv
|
||||
static const float cube_vertices_textured[] =
|
||||
{
|
||||
-1.0f, -1.0f, 1.0f, 1.0f, 0,0,1, 0.75,0.25,//0//back
|
||||
1.0f, -1.0f, 1.0f, 1.0f, 0,0,1, 1,0.25 ,//1
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 0,0,1, 1,0,//2
|
||||
-1.0f, 1.0f, 1.0f, 1.0f, 0,0,1, 0.75,0,//3
|
||||
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, 0,0,-1, 0.5,0.25,//4//front
|
||||
1.0f, -1.0f, -1.0f, 1.0f, 0,0,-1, 0.25,0.25,//5
|
||||
1.0f, 1.0f, -1.0f, 1.0f, 0,0,-1, 0.25,0,//6
|
||||
-1.0f, 1.0f, -1.0f, 1.0f, 0,0,-1, 0.5,0,//7
|
||||
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, -1,0,0, 0.5,0,//Right
|
||||
-1.0f, 1.0f, -1.0f, 1.0f, -1,0,0, 0.75,0,
|
||||
-1.0f, 1.0f, 1.0f, 1.0f, -1,0,0, 0.75,0.25,
|
||||
-1.0f, -1.0f, 1.0f, 1.0f, -1,0,0, 0.5,0.25,
|
||||
|
||||
1.0f, -1.0f, -1.0f, 1.0f, 1,0,0, 0.25,0.5,//Left
|
||||
1.0f, 1.0f, -1.0f, 1.0f, 1,0,0, 0.25,0.25,
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 1,0,0, 0.,.25,
|
||||
1.0f, -1.0f, 1.0f, 1.0f, 1,0,0, 0,.5,
|
||||
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, 0,-1,0, 0.25,0.5,//bottom
|
||||
-1.0f, -1.0f, 1.0f, 1.0f, 0,-1,0, 0.25,0.25,
|
||||
1.0f, -1.0f, 1.0f, 1.0f, 0,-1,0, 0.5,0.25,
|
||||
1.0f,-1.0f, -1.0f, 1.0f, 0,-1,0, 0.5,0.5,
|
||||
|
||||
-1.0f, 1.0f, -1.0f, 1.0f, 0,1,0, 0,0,//top
|
||||
-1.0f, 1.0f, 1.0f, 1.0f, 0,1,0, 0,0.25,
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 0,1,0, 0.25,0.25,
|
||||
1.0f,1.0f, -1.0f, 1.0f, 0,1,0, 0.25,0,
|
||||
};
|
||||
|
||||
|
||||
|
||||
///position xyz, unused w, normal, uv
|
||||
static const float cube_vertices2[] =
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.8 KiB |
BIN
data/cube.png
Normal file
BIN
data/cube.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
Reference in New Issue
Block a user