How to use SageMaker, BlazingText, and Labeling Jobs - amazon-sagemaker

I have done some searching on how to use the UI console for creating a ground truth labeling job to creating a model from this labeling job and not getting the outputs I expect.
The first question is, I have labeled probably a hundred parts of a text in the ground truth job and submitted the labels. But when I look at the labeled objects/total, it shows 0.
Then, after creating a training job from the ground truth labeling job's output, creating a model package from the training job, and finally creating a batch transform job from that model package, the output from the batch transform job is not what is expected.
The expected output should be a json object containing the the text with the label, but the output I'm getting is below.
What do I need to do to get the expected results?
[{"vector": http://0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, "word": "t-6 - hard leather tobacco r11 24\" x 48\" = 744 sf"}, {"vector": http://0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, "word": "t-6 - hard leather tobacco r11 24\" x 48\" = 264 sf"}, {"vector":...

I'm an engineer on the SageMaker service team. As a starting point, I would encourage you to look through this sample notebook (if you haven't already) that demonstrates how to train BlazingText for text classification purposes (https://github.com/awslabs/amazon-sagemaker-examples/blob/master/introduction_to_amazon_algorithms/blazingtext_text_classification_dbpedia/blazingtext_text_classification_dbpedia.ipynb). There are a few nuances here, e.g., be sure that the "mode" parameter is set to "supervised". Please note that this example will not exactly mirror your use case - I understand you're trying to use the SageMaker augmented manifest format for training, whereas this example uses a different input format - but it's still an illustrative resource.
In order to help answer your questions more deeply, I'd like to see more information on the specific resources involved here. For privacy/security reasons, I don't want to ask you to expose those in this SO thread. Would you please submit a support ticket through your AWS account? Don't worry about exactly where it gets sent - if you can provide the ticket number, I'll make sure it gets routed back to us.

Related

Access a value in a 2D array through programming in Swift

I create Aliment struct.
And i have an array of Aliment.
struct Aliment {
let name: String
let vitamineARetinol: Float
let vitaminC: Float
let vitaminD: Float
let calories: Float
let grammage: Float
}
let ListAlimentsBrut = [
Aliment(name: "Orange", vitamineARetinol: 0.5, vitaminC: 57, vitaminD: 0.98, calories: 140, grammage: 100),
Aliment(name: "Pomme", vitamineARetinol: 0.2, vitaminC: 6.25, vitaminD: 0.38, calories: 120, grammage: 100),
Aliment(name: "Poire", vitamineARetinol: 0.1, vitaminC: 4.62, vitaminD: 0.58, calories: 140, grammage: 100),
Aliment(name: "Laitue", vitamineARetinol: 0.3, vitaminC: 4.72, vitaminD: 0.92, calories: 105, grammage: 100),
Aliment(name: "Laitue", vitamineARetinol: 0.7, vitaminC: 4.72, vitaminD: 0.63, calories: 122, grammage: 100),
Aliment(name: "Poivron Jaune", vitamineARetinol: 0, vitaminC: 184, vitaminD: 0, calories: 29.2, grammage: 100)
]
how can i access the calorie value of the second food, i mean 120 calories for "Pomme", but through programming and not directly.
Thank you.
You can access the second element of the an array using the subscript method (arrayProperty[index]), note that the first element has an index of 0, in your case :
ListAlimentsBrut[1].calories
Also, I would recommend to follow the naming convention in swift meaning that the property ListAlimentsBrut should start with a lower case and to name the property without saying the type of the data (here list)and keeping consistency between language (just english, not a mix of french and english) like that for exemple :
let rawIngredients = [...]

Why the render buffer data is different produced by the same pipe line in OpenGL?

The whole codes:
//two triangles color and position data
Vertex Verts[9] = {
{ { 255,0,0,255 },{ 0.0f, 0.9f, 0.0f } },
{ { 0,255,0,255 },{ -0.9f, -0.9f, 0.0f } },
{ { 0,0,255,255 },{ 0.9f, -0.9f, 0.0f } } ,
{ { 255,255,255,255 },{ 0.0f, 0.8f, -0.2f } } ,
{ { 255,255,255,255 },{ -0.4f, 0.0f, -0.2f } } ,
{ { 255,255,255,255 },{ 0.4f, 0.0f, -0.2f } } ,
};
GLuint Program = 0;
GLuint vert;
GLuint vbo;
GLuint RendBuf[4], FrameBuf[2];
This is buffer set codes:
void Init()
{
glGenVertexArrays(1, &vert);
glBindVertexArray(vert);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Verts), Verts, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), BUFFER_OFFSET(0));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(Verts->color)));
glEnableVertexAttribArray(1);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glUseProgram(Program);
I generate 4 render buffer,one depth buffer,three color buffer:
glGenRenderbuffers(4, RendBuf);
glBindRenderbuffer(GL_RENDERBUFFER, RendBuf[0]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 200, 200);
glBindRenderbuffer(GL_RENDERBUFFER, RendBuf[1]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 200, 200);
glBindRenderbuffer(GL_RENDERBUFFER, RendBuf[2]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 200, 200);
glBindRenderbuffer(GL_RENDERBUFFER, RendBuf[3]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 200, 200);
//all buffer objects are bound to framebuffer object:FrameBuf[0]
glGenFramebuffers(1, &FrameBuf[0]);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FrameBuf[0]);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, RendBuf[0]);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, RendBuf[2]);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RendBuf[1]);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, RendBuf[3]);
}
This is render code:
void Display()
{
//draw in framebuffer
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FrameBuf[0]);
glViewport(0, 0, 200, 200);
GLenum bufs[3] = { GL_COLOR_ATTACHMENT0 , GL_COLOR_ATTACHMENT1 , GL_COLOR_ATTACHMENT2};
glDrawBuffers(3,bufs);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
change the background color of three triangles
float Color[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, Color);
float Color1[] = { 1.0f, 1.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 1, Color1);
float Color2[] = { 0.0f, 1.0f, 1.0f, 1.0f };
glClearBufferfv(GL_COLOR, 2, Color2);
glBindVertexArray(vert);
glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLES, 0, 6);
copy the data from framebuffer to screen buffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, FrameBuf[0]);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glViewport(0, 0, 400, 400);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, 200, 200, 0, 0, 200, 200, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, 200, 200, 200, 0, 400, 200,GL_COLOR_BUFFER_BIT, GL_NEAREST);
glReadBuffer(GL_COLOR_ATTACHMENT2);
glBlitFramebuffer(0, 0, 200, 200, 0, 200, 200, 400,GL_COLOR_BUFFER_BIT, GL_NEAREST);
glutSwapBuffers();
}
the vertex shader and fragment shader:
layout(location = 0) in vec4 vColor;
layout(location = 1) in vec4 vPos;
void main()
{
gl_Position = vPos;
color = vColor;
}
layout(location = 0) out vec4 fColor;
layout(location = 1) out vec4 fColor2;
void main()
{
fColor = color;
fColor2 = vec4(0.0, 0.0, 1.0, 1.0);
}
The first triangle is correct,the second is a blue triangle on yellow background,the third one is just light blue background.

How can I make my light stay fixed relative to my scene (in the cube)?

I've been drawing Cornell box. I want to place light in my lamp(lamp is a white cube placed on the right wall). It will make an illusion that lamp is shining. But I can't place my light into the cube. I have tried to Set the view transform and then set light position, but it doesn't work.
Here is my simple code: ( lamp cube has been moved glTranslatef(0.63, 0.3, 0.0))
void display(void)
{
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, 600, 600);
glClearColor(0.32, 0.32, 0.32, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw cube
glPushMatrix();
glTranslatef(0.2, -0.3, 0.4);
glColor3d(1.0, 0.38, 0.0);
glutSolidCube(0.2);
glPopMatrix();
// draw sphere
glPushMatrix();
glTranslatef(0.2, -0.1, 0.4);
glColor3d(0.71, 0.0, 0.59);
glutSolidSphere(0.1,100,100);
glPopMatrix();
// draw parallelepiped
glPushMatrix();
glTranslatef(-0.2, -0.2, 0.25);
glRotatef(20, 0.0, 1.0, 0.0);
glColor3d(1.0, 0.38, 0.0);
glScalef(1, 1.8, 1);
glutSolidCube(0.2);
glPopMatrix();
// draw lamp
glPushMatrix();
glTranslatef(0.63, 0.3, 0.0);
glScalef(1.5, 0.3, 1);
glColor3d(1.0, 1.0, 1.0);
glutSolidCube(0.2);
glPopMatrix();
glBegin(GL_QUADS);
glNormal3f(0, 1.0, 0);
glColor3d(0.69, 0.69, 0.69); // bottom
glVertex3d(-0.5, -0.5, 0.5);
glVertex3d(-0.5, -0.5, -0.5);
glVertex3d(0.5, -0.5, -0.5);
glVertex3d(0.5, -0.5, 0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0, -1.0, 0);
glColor3d(0.69, 0.69, 0.69); // top
glVertex3d(-0.5, 0.5, 0.5);
glVertex3d(-0.5, 0.5, -0.5);
glVertex3d(0.5, 0.5, -0.5);
glVertex3d(0.5, 0.5, 0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glColor3d(0.0, 0.79, 0.05); // right
glVertex3d(0.5, -0.5, 0.5);
glVertex3d(0.5, 0.5, 0.5);
glVertex3d(0.5, 0.5, -0.5);
glVertex3d(0.5, -0.5, -0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(1.0, 0.0, 0.0);
glColor3d(1.0, 0.16, 0.0); // left
glVertex3d(-0.5, -0.5, 0.5);
glVertex3d(-0.5, 0.5, 0.5);
glVertex3d(-0.5, 0.5, -0.5);
glVertex3d(-0.5, -0.5, -0.5);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glColor3d(0.69, 0.69, 0.69); // back
glVertex3d(-0.5, -0.5, -0.5);
glVertex3d(-0.5, 0.5, -0.5);
glVertex3d(0.5, 0.5, -0.5);
glVertex3d(0.5, -0.5, -0.5);
glEnd();
glFlush();
glPopMatrix();
glutSwapBuffers();
}
void Initialize() {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat global_ambient[] = { 0.1, 0.1, 0.1, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
GLfloat ambient[] = { 0.0,0.0,0.0,1.0 };
GLfloat diffuse[] = { 1.0,1.0,1.0,1.0 };
GLfloat spec[] = { 1,1,1,1 };
GLfloat specref[] = { 1,1,1,1 };
GLfloat lpos[] = { 0.0, 0.0, 0.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, spec);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specref);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 64);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
}
void exitFunc(unsigned char key, int x, int y) {
switch (key) {
case 27:
exit(0);
break;
}
}
void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.35, 0.35, -0.35, 0.35, 1.2, 400.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0, 0, -2);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Cornell Box");
Initialize();
glutDisplayFunc(display);
glutKeyboardFunc(exitFunc);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
Note, that drawing by glBegin/glEnd sequences, the fixed function pipeline matrix stack and fixed function pipeline per vertex light model, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
Anyway, when the light position is set by glLightfv(GL_LIGHT0, GL_POSITION, pos), then
pos is multiplied by the current model view matrix.
This means if the position is set before the model view matrix is set, then the light position is placed in absolut coordinates to the world.
If it is set after the model view matrix was set, then the light position can be set in the coordinate system of the model.
Set the light position when you draw the lamp, to the center of the "lamp":
// draw lamp
glPushMatrix();
glTranslatef(0.63, 0.3, 0.0);
glScalef(1.5, 0.3, 1);
GLfloat lpos[] = { 0.0, 0.0, 0.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glColor3d(1.0, 1.0, 1.0);
glutSolidCube(0.2);
glPopMatrix();
The OpenGL fixed function pipeline calculates the light per vertex: Gouraud shading.
This may cause, that you can't "see" the light, if the light vector hits the vertex coordinate by a acute angle relative to the plane of the surface.
In your case the green wall is almost unlit, because the light source is almost directly on the wall. The lam itself is not lit, because the light source is inside the lamp and it is light from the backside.
See OpenGL Lighting on texture plane is not working
Change the light position slightly, to put it in front of the wall, and tessellate the right wall to 4 quads, to "see" what I mean:
GLfloat lpos[] = { -0.1, 0.0, 0.0, 1.0 };
// right
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glColor3d(0.0, 0.79, 0.05);
glVertex3d(0.5, 0.3, 0.5);
glVertex3d(0.5, 0.5, 0.5);
glVertex3d(0.5, 0.5, 0.0);
glVertex3d(0.5, 0.3, 0.0);
glVertex3d(0.5, 0.3, 0.0);
glVertex3d(0.5, 0.5, 0.0);
glVertex3d(0.5, 0.5, -0.5);
glVertex3d(0.5, 0.3, -0.5);
glVertex3d(0.5, -0.5, 0.5);
glVertex3d(0.5, 0.3, 0.5);
glVertex3d(0.5, 0.3, 0.0);
glVertex3d(0.5, -0.5, 0.0);
glVertex3d(0.5, -0.5, 0.0);
glVertex3d(0.5, 0.3, 0.0);
glVertex3d(0.5, 0.3, -0.5);
glVertex3d(0.5, -0.5, -0.5);
glEnd();

How to use GL_TEXTURE_2D_ARRAY on OpenGL using VBO

I'm trying to draw an arbitrary object with "n" number of textures (6 in the examples), and each face has a single (but possibly different) texture.
When using a single texture, it all works fine, but I'm having a hard time making 2D texture arrays to work.
Here's the object:
struct Vertex3f { float x, y, z; };
struct ObjectVertexfMT { // MT stands for Multi Texture
struct Vertex3f coord;
struct Vertex3f texcoord;
struct Vertex3f normal;
};
struct ObjectVertexfMT GLEngine_CubeMT[] = {
// x, y, v, u, v, r, nx, ny, nz
// Front
{ -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f },
{ -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f },
// Back
{ -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f },
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f },
{ -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f },
// Top
{ -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 2.0f, 0.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 2.0f, 0.0f, 1.0f, 0.0f },
// Bottom
{ -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 3.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 3.0f, 0.0f, -1.0f, 0.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 3.0f, 0.0f, -1.0f, 0.0f },
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 3.0f, 0.0f, -1.0f, 0.0f },
// Right
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 4.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 4.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 4.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 4.0f, 1.0f, 0.0f, 0.0f },
// Left
{ -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 5.0f, -1.0f, 0.0f, 0.0f },
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 5.0f, -1.0f, 0.0f, 0.0f },
{ -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 5.0f, -1.0f, 0.0f, 0.0f },
{ -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 5.0f, -1.0f, 0.0f, 0.0f }
};
note that the "r" parameter is different for each quad (indicating the index of the texture that I want in that specific quad).
I'm registering the textures like so:
struct texInfo {
int width, height;
unsigned char *data;
};
// Loads texture from filename in a texInfo structure -- always 32 bit depth
struct texInfo *loadTexture(const char* filename);
unsigned int register3DTexture(const char *filenames[], unsigned int texcount) {
unsigned int ret;
unsigned int i;
struct texInfo *tex;
glGenTextures(1, &ret);
glBindTexture(GL_TEXTURE_2D_ARRAY, ret);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, 4, 256, 256, 6, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
for (i = 0; i < texcount; i++) {
tex = loadTexture(filenames[i]);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, tex->width, tex->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, tex->data);
free(tex);
}
return(ret);
}
...and then I draw:
glPushMatrix();
glClientActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, textures[0]); // Same behaviour if I change to GL_TEXTURE_2D
glTranslatef(pos.x, pos.y, pos.z);
glRotatef(rot_angle, rot.x, rot.y, rot.z);
glBindBuffer(GL_ARRAY_BUFFER, VobObject[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VobObject[1]);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(struct ObjectVertexfMT), 0);
glNormalPointer(GL_FLOAT, sizeof(struct ObjectVertexfMT), (void*)(sizeof(float) * 6));
// Textures
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(struct ObjectVertexfMT), (void*)(sizeof(float) * 3));
glDrawElements(GL_QUADS, m_vertexcount, GL_UNSIGNED_SHORT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopMatrix();
The object is correctly drawn, but with no textures.
Another few questions:
Assuming it works, is this the best way to achieve my goal?
Can the "subtextures" have different dimensions of the "main" texture (the
parameters of width and height on glTexImage3D() may be different
from the ones from glTexSubImage3D())?
You must use a shader to use array textures. You can't use them with fixed-function rendering.
Can the "subtextures" have different dimensions of the "main" texture (the parameters of width and height on glTexImage3D() may be different from the ones from glTexSubImage3D())?
This question is confused. Just as with C++ arrays, the elements of texture arrays are all the same. If you have an array of int[30] in C++, then every element will be 30 integers in size. The same goes for array textures. The 2D array texture as a whole has a width and height, which is the same for all of the textures in the array.
glTexSubImage3D (and similar functions) does not affect the dimensions of the texture. All it does is upload pixel data to a location in the texture. Only glTexImage3D (and similar functions) affect the dimensions of the texture.

how to eliminate: [Warning] converting to `int' from `double'

I have the following code with a structure array with data to make some calculations. When I compile the code I get the message [Warning] converting to 'int' from 'double'. I would like to fix this problem with the code but I'm not sure where the problem is. I'm not sure if this warning is too big of a deal but I think that this converting could be causing some discrepancies in my calculations as well.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int i,aplha[90],beta[90];
double gamma[90],delta[90],epsilon[90],zeta[90];
struct wmm
{
int alpha;
int beta;
double gamma;
double delta;
double epsilon;
double zeta;
}book[]={
{1, 0, -29496.6, 0.0, 11.6, 0.0},
{1, 1, -1586.3, 4944.4, 16.5, -25.9},
{2, 0, -2396.6, 0.0, -12.1, 0.0},
{2, 1, 3026.1, -2707.7, -4.4, -22.5},
{2, 2, 1668.6, -576.1, 1.9, -11.8},
{3, 0, 1340.1, 0.0, 0.4, 0.0},
{3, 1, -2326.2, -160.2, -4.1, 7.3},
{3, 2, 1231.9, 251.9, -2.9, -3.9},
{3, 3, 634.0, -536.6, -7.7, -2.6},
{4, 0, 912.6, 0.0, -1.8, 0.0},
{4, 1, 808.9, 286.4, 2.3, 1.1},
{4, 2, 166.7, -211.2, -8.7, 2.7},
{4, 3, -357.1, 164.3, 4.6, 3.9},
{4, 4, 89.4, -309.1, -2.1, -0.8},
{5, 0, -230.9, 0.0, -1.0, 0.0},
{5, 1, 357.2, 44.6, 0.6, 0.4},
{5, 2, 200.3, 188.9, -1.8, 1.8},
{5, 3, -141.1, -118.2, -1.0, 1.2},
{5, 4, -163.0, 0.0, 0.9, 4.0},
{5, 5, -7.8, 100.9, 1.0, -0.6},
{6, 0, 72.8, 0.0, -0.2, 0.0},
{6, 1, 68.6, -20.8, -0.2, -0.2},
{6, 2, 76.0, 44.1, -0.1, -2.1},
{6, 3, -141.4, 61.5 , 2.0, -0.4},
{6, 4, -22.8, -66.3, -1.7, -0.6},
{6, 5, 13.2, 3.1, -0.3, 0.5},
{6, 6, -77.9, 55.0, 1.7, 0.9},
{7, 0, 80.5, 0.0, 0.1, 0.0},
{7, 1, -75.1, -57.9, -0.1, 0.7},
{7, 2 -4.7, -21.1, -0.6, 0.3},
{7, 3, 45.3, 6.5, 1.3, -0.1},
{7, 4, 13.9, 24.9, 0.4, -0.1},
{7, 5, 10.4, 7.0, 0.3, -0.8},
{7, 6, 1.7, -27.7, -0.7, -0.3},
{7, 7, 4.9, -3.3, 0.6, 0.3},
{8, 0, 24.4, 0.0, -0.1, 0.0},
{8, 1, 8.1, 11.0, 0.1, -0.1},
{8, 2, -14.5, -20.0, -0.6, 0.2},
{8, 3, -5.6, 11.9, 0.2, 0.4},
{8, 4, -19.3, -17.4, -0.2, 0.4},
{8, 5, 11.5, 16.7, 0.3, 0.1},
{8, 6, 10.9, 7.0, 0.3, -0.1},
{8, 7, -14.1, -10.8, -0.6, 0.4},
{8, 8, -3.7, 1.7, 0.2, 0.3},
{9, 0, 5.4, 0.0, 0.0, 0.0},
{9, 1, 9.4, -20.5, -0.1, 0.0},
{9, 2, 3.4, 11.5, 0.0, -0.2},
{9, 3, -5.2, 12.8, 0.3, 0.0},
{9, 4, 3.1, -7.2, -0.4, -0.1},
{9, 5, -12.4, -7.4, -0.3, 0.1},
{9, 6, -0.7, 8.0, 0.1, 0.0},
{9, 7, 8.4, 2.1, -0.1, -0.2},
{9, 8, -8.5, -6.1, -0.4, 0.3},
{9, 9, -10.1, 7.0, -0.2, 0.2},
{10, 0, -2.0, 0.0, 0.0, 0.0},
{10, 1, -6.3, 2.8, 0.0, 0.1},
{10, 2, 0.9, -0.1, -0.1, -0.1},
{10, 3, -1.1, 4.7, 0.2, 0.0},
{10, 4, -0.2, 4.4, 0.0, -0.1},
{10, 5, 2.5, -7.2, -0.1, -0.1},
{10, 6, -0.3, -1.0, -0.2, 0.0},
{10, 7, 2.2, -3.9, 0.0, -0.1},
{10, 8, 3.1, -2.0, -0.1, -0.2},
{10, 9, -1.0, -2.0, -0.2, 0.0},
{10, 10, -2.8, -8.3, -0.2, -0.1},
{11, 0, 3.0, 0.0, 0.0, 0.0},
{11, 1, -1.5, 0.2, 0.0, 0.0},
{11, 2, -2.1, 1.7, 0.0, 0.1},
{11, 3, 1.7, -0.6, 0.1, 0.0},
{11, 4, -0.5, -1.8, 0.0, 0.1},
{11, 5, 0.5, 0.9, 0.0, 0.0},
{11, 6, -0.8, -0.4, 0.0, 0.1},
{11, 7, 0.4, -2.5, 0.0, 0.0},
{11, 8, 1.8, -1.3, 0.0, -0.1},
{11, 9, 0.1, -2.1, 0.0, -0.1},
{11, 10, 0.7, -1.9, -0.1, 0.0},
{11, 11, 3.8, -1.8, 0.0, -0.1},
{12, 0, -2.2, 0.0, 0.0, 0.0},
{12, 1, -0.2, -0.9, 0.0, 0.0},
{12, 2, 0.3, 0.3, 0.1, 0.0},
{12, 3, 1.0, 2.1, 0.1, 0.0},
{12, 4, -0.6, -2.5, -0.1, 0.0},
{12, 5, 0.9, 0.5, 0.0, 0.0},
{12, 6, -0.1, 0.6, 0.0, 0.1},
{12, 7, 0.5, 0.0, 0.0, 0.0},
{12, 8, -0.4, 0.1, 0.0, 0.0},
{12, 9, -0.4, 0.3, 0.0, 0.0},
{12, 10, 0.2, -0.9, 0.0, 0.0},
{12, 11, -0.8, -0.2, -0.1, 0.0},
{12, 12, 0.0, 0.9, 0.1, 0.0}};
}
{7, 2 -4.7, -21.1, -0.6, 0.3},
instead of
{7, 2, -4.7, -21.1, -0.6, 0.3},
(missing coma) Line 50.

Resources