int modelEngine::loadWavefrontModel(char *path)
{
	// If we have room for models
	if(numModels < MAX_MODELS - 1)
	{
		// Try load model
		models[numModels] = load_wavefront(path, NULL);
		// If load successfull
		if(models[numModels] != 0)
		{
			// Enable model
			WAVEFRONT_MODEL_T *model = (WAVEFRONT_MODEL_T *)models[numModels];
			model->modelEnabled = 1;
			// Set model text
			modelText[numModels].textReady = 0;
			numModels++;
			// Return model index
			return numModels - 1;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		return -1;
	}
}
Beispiel #2
0
int main ()
{
   bcm_host_init();
   printf("Note: ensure you have sufficient gpu_mem configured\n");

   // Clear application state
   memset( state, 0, sizeof( *state ) );
      
   // Start OGLES
   init_ogl(state);

   // Setup the model world
   init_model_proj(state);

   // initialise the OGLES texture(s)
   init_textures(state);

   //state->model = cube_wavefront();
   state->model = load_wavefront("teapot.obj.dat", NULL);

   while (!terminate)
   {
      update_model(state);
      redraw_scene(state);
   }
   exit_func();
   return 0;
}
Beispiel #3
0
static int teapot_gl_init(RASPITEX_STATE *raspitex_state)
{
    const char *model_path = "/opt/vc/src/hello_pi/hello_teapot/teapot.obj.dat";
    TEAPOT_STATE_T *state = NULL;
    int rc = 0;

    // Clear scene state
    state = calloc(1, sizeof(TEAPOT_STATE_T));
    raspitex_state->scene_state = state;
    state->screen_width = raspitex_state->width;
    state->screen_height = raspitex_state->height;

    rc = raspitexutil_gl_init_1_0(raspitex_state);
    if (rc != 0)
        goto end;

    // Start OGLES
    init_ogl(state);

    // Setup the model world
    init_model_proj(state);
    state->model = load_wavefront(model_path, NULL);

    if (! state->model)
    {
        vcos_log_error("Failed to load model from %s\n", model_path);
        rc = -1;
    }

end:
    return rc;
}
Beispiel #4
0
/* Initialize the scene */
void init(char * object, char * diffuse, char * sphere) {
	load_wavefront(object);
	/* Check for GLEW compatibility */
#if 0
	glewInit();
	if (glewIsSupported("GL_VERSION_2_0")) {
		printf("Ready.\n");
	} else {
		/* We don't have OpenGL 2.0 support! BAIL! */
		printf("wtf?\n");
		exit(1);
	}
#endif

	/* Some nice defaults */
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);

	/* Initialize the two textures */
	char * texture;
	int32_t size;
	int dif_size, env_size;
	glGenTextures(1,&texture_a);
	glGenTextures(1,&texture_b);
	/* Diffuse texture { */
	/* The diffuse texture is a wood texture */
	texture = readFile(diffuse, &size); /* We have stored are textures as raw RGBA */
	dif_size = (int)sqrt(size / 4);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, texture_a);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, dif_size, dif_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
	free(texture);
	/* } */
	/* Sphere map texture { */
	texture = readFile(sphere, &size);
	env_size = (int)sqrt(size / 4);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, texture_b);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, env_size, env_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
	free(texture);
	/* } */

	/* Load in the shader programs */
	char *vs = NULL,
		 *fs = NULL;
	int32_t v_size, f_size;
	v = glCreateShader(GL_VERTEX_SHADER);
	f = glCreateShader(GL_FRAGMENT_SHADER);
	vs = readFile("teapot.vert", &v_size); /* Vertex shader */
	fs = readFile("teapot.frag", &f_size); /* Fragment shader */
	glShaderSource(v, 1, &vs, (GLint *)&v_size); /* Load... */
	glShaderSource(f, 1, &fs, (GLint *)&f_size);
	free(vs); free(fs); /* Free the data blobs */
	glCompileShader(v); /* Compile... */
	glCompileShader(f);
	p = glCreateProgram(); /* Create a program */
	glAttachShader(p, v);  /* Attach the two shaders */
	glAttachShader(p, f);
	glLinkProgram(p);      /* Link it all together */

	/* Use our shaders */
	glUseProgram(p);

	/* Set the texture sources */
	GLint tex0 = glGetUniformLocation(p, "texture");
	GLint tex1 = glGetUniformLocation(p, "spheremap");
	glUniform1i(tex0, 0);
	glUniform1i(tex1, 1);

	/* Check for errors */
	GLenum glErr;
	int    retCode = 0;
	glErr = glGetError();
	while (glErr != GL_NO_ERROR)
	{
		//printf("glError: %s\n", gluErrorString(glErr));
		retCode = 1;
		glErr = glGetError();
	}


}
Beispiel #5
0
geometry_file::geometry_file( const crap::string256& filename, file_type type, crap::memory_pool* pool ) : _vertices_index(0), _uvs_index(0), _normals_index(0), 
	_face_index(0), _group_index(0), _material_index(0), _vertices(0), _uvs(0), _normals(0), _faces(0), _groups(0), _material_groups(0), _content_pool(pool)
{
	if( type == wavefront )
		load_wavefront( filename );
}