Пример #1
0
void		sphere_texturing(t_obj *obj, t_3d_pos *ray,
				 double alpha, t_mat *mat)
{
  double	x;
  double	y;
  int		height;
  int		width;
  t_3d_pos	hit;

  x = alpha;
  if (obj->sphe.texture != NULL)
    {
      hit = find_hit(alpha, &ray[0], &ray[1]);
      height = (obj->sphe.texture->clipable.clip_height) * obj->sphe.y_repeat;
      width = (obj->sphe.texture->clipable.clip_width) * obj->sphe.x_repeat;
      x = width * (0.5 - (atan2(hit.z - CZ, hit.x - CX) / M_PI));
      y = height * (0.5 - (asin((hit.y - CY) / obj->sphe.rad) / M_PI));
      mat->color.full = get_texture_color(obj->sphe.texture, x, y);
    }
}
Пример #2
0
/** \return GL_TRUE for pass, GL_FALSE for fail */
static GLboolean
test_format(const struct format_info *info)
{
    const int comps = num_components(info->BaseFormat);
    const int texels = TexWidth * TexHeight;
    const int w = piglit_width / 10;
    const int h = piglit_height / 10;
    GLfloat expected[4];
    void *image;
    float value[4];
    GLint f;
    GLenum userFormat;
    int p;

    if ((info->BaseFormat == GL_RED ||
            info->BaseFormat == GL_RG) && !HaveRG) {
        /* skip it */
        return GL_TRUE;
    }

    /*printf("Testing %s\n", info->Name);*/

    get_texture_color(value);

    /* alloc, fill texture image */
    image = malloc(comps * texels * sizeof(GLfloat));
    fill_array(comps, texels, image, value);

    /* GL_INTENSITY is not a legal src format */
    userFormat = info->BaseFormat == GL_INTENSITY ? GL_LUMINANCE : info->BaseFormat;

    glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
                 userFormat, GL_FLOAT, image);
    free(image);

    if (check_error(__FILE__, __LINE__))
        return GL_FALSE;

    /* check internal format */
    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &f);
    if (f != info->IntFormat) {
        printf("%s: GL_TEXTURE_INTERNAL_FORMAT query failed for 0x%x\n",
               TestName,
               info->IntFormat);
        return GL_FALSE;
    }

    /* check texture datatype info */
    {
        static const GLenum queries[] = {
            GL_TEXTURE_RED_TYPE_ARB,
            GL_TEXTURE_GREEN_TYPE_ARB,
            GL_TEXTURE_BLUE_TYPE_ARB,
            GL_TEXTURE_ALPHA_TYPE_ARB,
            GL_TEXTURE_LUMINANCE_TYPE_ARB,
            GL_TEXTURE_INTENSITY_TYPE_ARB,
            GL_TEXTURE_DEPTH_TYPE_ARB
        };
        static const char *queryNames[] = {
            "GL_TEXTURE_RED_TYPE_ARB",
            "GL_TEXTURE_GREEN_TYPE_ARB",
            "GL_TEXTURE_BLUE_TYPE_ARB",
            "GL_TEXTURE_ALPHA_TYPE_ARB",
            "GL_TEXTURE_LUMINANCE_TYPE_ARB",
            "GL_TEXTURE_INTENSITY_TYPE_ARB",
            "GL_TEXTURE_DEPTH_TYPE_ARB"
        };
        int i;
        for (i = 0; i < ARRAY_SIZE(queries); i++) {
            GLint type = 1;
            glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, queries[i], &type);
            if (check_error(__FILE__, __LINE__))
                return GL_FALSE;
            if (type != GL_NONE && type != GL_FLOAT) {
                printf("%s: %s query failed (returned 0x%x)\n",
                       TestName, queryNames[i], type);
                return GL_FALSE;
            }
        }
    }

    /* compute expected color */
    switch (info->BaseFormat) {
    case GL_RGBA:
        expected[0] = scale_and_bias(value[0]);
        expected[1] = scale_and_bias(value[1]);
        expected[2] = scale_and_bias(value[2]);
        expected[3] = scale_and_bias(value[3]);
        break;
    case GL_RGB:
        expected[0] = scale_and_bias(value[0]);
        expected[1] = scale_and_bias(value[1]);
        expected[2] = scale_and_bias(value[2]);
        expected[3] = scale_and_bias(1.0);
        break;
    case GL_ALPHA:
        expected[0] =
            expected[1] =
                expected[2] = scale_and_bias(0.0);
        expected[3] = scale_and_bias(value[0]);
        break;
    case GL_LUMINANCE:
        expected[0] =
            expected[1] =
                expected[2] = scale_and_bias(value[0]);
        expected[3] = scale_and_bias(1.0);
        break;
    case GL_INTENSITY:
        expected[0] =
            expected[1] =
                expected[2] =
                    expected[3] = scale_and_bias(value[0]);
        break;
    case GL_LUMINANCE_ALPHA:
        expected[0] =
            expected[1] =
                expected[2] = scale_and_bias(value[0]);
        expected[3] = scale_and_bias(value[1]);
        break;
    case GL_RED:
        expected[0] = scale_and_bias(value[0]);
        expected[1] = scale_and_bias(0.0);
        expected[2] = scale_and_bias(0.0);
        expected[3] = scale_and_bias(1.0);
        break;
    case GL_RG:
        expected[0] = scale_and_bias(value[0]);
        expected[1] = scale_and_bias(value[1]);
        expected[2] = scale_and_bias(0.0);
        expected[3] = scale_and_bias(1.0);
        break;
    default:
        abort();
    }

    /* draw */
    glClearColor(0.5, 0.5, 0.5, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glTexCoord2f(0, 0);
    glVertex2f(0, 0);
    glTexCoord2f(1, 0);
    glVertex2f(w, 0);
    glTexCoord2f(1, 1);
    glVertex2f(w, h);
    glTexCoord2f(0, 1);
    glVertex2f(0, h);
    glEnd();

    /* test */
    p = piglit_probe_pixel_rgba(w/2, h/2, expected);
    if (!p) {
        int i;

        printf("  Failed with format %s:\n", info->Name);
        printf("  Texture color = ");
        for (i = 0; i < comps; i++) {
            printf("%f", value[i]);
            if (i + 1 < comps)
                printf(", ");
        }
        printf("\n");
    }

    glutSwapBuffers();

    return p;
}