Fixed a bug in how textures are displayed by nuklear and implemented saving transform informations for all entities, archetypes or not

dev
Shariq Shah 6 years ago
parent b8b4f13809
commit 33e07e5a52
  1. 4
      assets/scenes/Level_1.symtres
  2. 2
      src/common/parser.c
  3. 3
      src/game/debug_vars.c
  4. 2
      src/game/editor.c
  5. 37
      src/game/entity.c
  6. 2
      src/game/gui.c
  7. 19
      src/game/texture.c
  8. 12
      todo.txt

@ -16,9 +16,9 @@ Player
{ {
type : 2 type : 2
scale : 1.000 1.000 1.000 scale : 1.000 1.000 1.000
rotation : 0.000 -0.616 0.000 0.789 rotation : 0.000 -0.489 0.000 0.873
active : true active : true
position : -33.936 4.392 -38.211 position : -51.333 6.103 -36.095
name : Player name : Player
camera_clear_color : 0.298 0.600 0.898 1.000 camera_clear_color : 0.298 0.600 0.898 1.000
} }

@ -278,6 +278,8 @@ void parser_free(struct Parser *parser)
object->data = NULL; object->data = NULL;
object->type = PO_UNKNOWN; object->type = PO_UNKNOWN;
} }
array_free(parser->objects);
free(parser);
} }
struct Parser* parser_new(void) struct Parser* parser_new(void)

@ -140,7 +140,8 @@ void debug_vars_post_update(struct Debug_Vars* debug_vars)
case VT_INT: // Texture case VT_INT: // Texture
nk_layout_row_dynamic(context, debug_vars->row_height_texture, 2); nk_layout_row_dynamic(context, debug_vars->row_height_texture, 2);
nk_label(context, &variable->name[0], name_flags); nk_label(context, &variable->name[0], name_flags);
nk_image_color(context, nk_image_id(texture_get_texture_handle(variable->value.val_int)), nk_rgb_f(1.f, 1.f, 1.f)); //nk_image_color(context, nk_image_id(texture_get_texture_handle(variable->value.val_int)), nk_rgb_f(1.f, 1.f, 1.f));
nk_image_color(context, nk_image_id(variable->value.val_int), nk_rgb_f(1.f, 1.f, 1.f));
break; break;
case VT_VEC3: // Color RGB case VT_VEC3: // Color RGB
nk_layout_row_dynamic(context, debug_vars->row_height_color, 2); nk_layout_row_dynamic(context, debug_vars->row_height_color, 2);

@ -1499,6 +1499,8 @@ void editor_camera_update(struct Editor* editor, float dt)
debug_vars_show_texture("Editor Cam Depth", editor_camera->depth_tex); debug_vars_show_texture("Editor Cam Depth", editor_camera->depth_tex);
debug_vars_show_color_rgba("Editor Cam Clear Color", &editor_camera->clear_color); debug_vars_show_color_rgba("Editor Cam Clear Color", &editor_camera->clear_color);
debug_vars_show_int("Editor Cam Depth Index", editor_camera->depth_tex);
debug_vars_show_int("Editor Cam Render Index", editor_camera->render_tex);
} }
void editor_widget_color_combov3(struct nk_context* context, vec3* color, int width, int height) void editor_widget_color_combov3(struct nk_context* context, vec3* color, int width, int height)

@ -121,12 +121,9 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ
//hashmap_str_set(entity_data, "parent", parent ? parent->name : "NONE"); //hashmap_str_set(entity_data, "parent", parent ? parent->name : "NONE");
/* Transform */ /* Transform */
if(write_transform) hashmap_vec3_set(entity_data, "position", &entity->transform.position);
{ hashmap_vec3_set(entity_data, "scale", &entity->transform.scale);
hashmap_vec3_set(entity_data, "position", &entity->transform.position); hashmap_quat_set(entity_data, "rotation", &entity->transform.rotation);
hashmap_vec3_set(entity_data, "scale", &entity->transform.scale);
hashmap_quat_set(entity_data, "rotation", &entity->transform.rotation);
}
switch(entity->type) switch(entity->type)
{ {
@ -456,22 +453,18 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
} }
//If there's a parent entity then it means this is a child entity and we shoud load it's relative transform values //If there's a parent entity then it means this is a child entity and we shoud load it's relative transform values
if(parent_entity) vec3 position = { 0.f, 0.f, 0.f };
{ quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 position = { 0.f, 0.f, 0.f }; vec3 scale = { 1.f, 1.f, 1.f };
quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 scale = { 1.f, 1.f, 1.f }; if(hashmap_value_exists(object->data, "position")) position = hashmap_vec3_get(object->data, "position");
if(hashmap_value_exists(object->data, "rotation")) rotation = hashmap_quat_get(object->data, "rotation");
if(hashmap_value_exists(object->data, "position")) position = hashmap_vec3_get(object->data, "position"); if(hashmap_value_exists(object->data, "scale")) scale = hashmap_vec3_get(object->data, "scale");
if(hashmap_value_exists(object->data, "rotation")) rotation = hashmap_quat_get(object->data, "rotation");
if(hashmap_value_exists(object->data, "scale")) scale = hashmap_vec3_get(object->data, "scale"); transform_set_position(new_entity, &position);
transform_scale(new_entity, &scale);
transform_set_position(new_entity, &position); quat_mul(&new_entity->transform.rotation, &new_entity->transform.rotation, &rotation);
transform_scale(new_entity, &scale); transform_update_transmat(new_entity);
quat_mul(&new_entity->transform.rotation, &new_entity->transform.rotation, &rotation);
transform_update_transmat(new_entity);
}
return new_entity; return new_entity;
} }

@ -226,13 +226,13 @@ void gui_render(struct Gui* gui, enum nk_anti_aliasing AA)
(GLint)(cmd->clip_rect.w * scale.x), (GLint)(cmd->clip_rect.w * scale.x),
(GLint)(cmd->clip_rect.h * scale.y)); (GLint)(cmd->clip_rect.h * scale.y));
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
texture_unbind(cmd->texture.id);
offset += cmd->elem_count; offset += cmd->elem_count;
} }
nk_clear(&gui->context); nk_clear(&gui->context);
} }
shader_unbind(); shader_unbind();
texture_unbind(gui->font_tex);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0); glBindVertexArray(0);

@ -158,15 +158,24 @@ void texture_cleanup(void)
void texture_bind(int index) void texture_bind(int index)
{ {
assert(index > -1 && index < array_len(texture_list)); if(index < 0 || index >= array_len(texture_list))
glActiveTexture(GL_TEXTURE0 + texture_list[index].texture_unit); {
glBindTexture(GL_TEXTURE_2D, texture_list[index].handle); log_warning("Cannot bind invalid texture handle");
return;
}
GL_CHECK(glActiveTexture(GL_TEXTURE0 + texture_list[index].texture_unit));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, texture_list[index].handle));
} }
void texture_unbind(int index) void texture_unbind(int index)
{ {
glActiveTexture(GL_TEXTURE0 + texture_list[index].texture_unit); if(index < 0 || index >= array_len(texture_list))
glBindTexture(GL_TEXTURE_2D, 0); {
log_warning("Cannot unbind invalid texture handle");
return;
}
GL_CHECK(glActiveTexture(GL_TEXTURE0 + texture_list[index].texture_unit));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
} }
int load_img(FILE* file, GLubyte** image_data, int* width, int* height, int* fmt, int* internal_format) int load_img(FILE* file, GLubyte** image_data, int* width, int* height, int* fmt, int* internal_format)

@ -1,4 +1,5 @@
Todo: Todo:
- Command to create a placeholder entity of a particular type in a file
- Re-write/Overhaul bounding volumes and ray intersection - Re-write/Overhaul bounding volumes and ray intersection
- Reduce the opacity of wireframe around selected entity in editor - Reduce the opacity of wireframe around selected entity in editor
- Allow picking and selecting other entity types in editor i.e. the ones that don't have meshes - Allow picking and selecting other entity types in editor i.e. the ones that don't have meshes
@ -7,10 +8,14 @@ Todo:
this will prevent us from having needless amount of entities with only minor changes from one another this will prevent us from having needless amount of entities with only minor changes from one another
? Split up material declarations into their own separate files. Materials have a base material like Blinn or Unshaded and in the file we save an instance with modified properties. ? Split up material declarations into their own separate files. Materials have a base material like Blinn or Unshaded and in the file we save an instance with modified properties.
when we are assigning materials to entites, we assign the instance of a particular material to them. when we are assigning materials to entites, we assign the instance of a particular material to them.
? Change hierarchical transformations from parent/child to an entity having attachments/slots where another entity can be attached or mounted. This way we can have hierarchical transformations and not have to store
a whole enitity hierarchy when saving the entity. When loading the entity, we load the entity and see which entites are attached to it and get references to those entity in the scene, if they are not loaded we could
either load them there and then or complain to the scene that we couldn't find the attachements and just carry on as usual
- When loading entities, show an additional optional textfield where user can enter the name they want for the entity after it is loaded - When loading entities, show an additional optional textfield where user can enter the name they want for the entity after it is loaded
- Add editor undo for transformation operations - Add editor undo for transformation operations
- Decide how to handle scale when checking sphere-ray intersection - Decide how to handle scale when checking sphere-ray intersection
- Add material export for blender exporter? - Add material export for blender exporter?
- Show current filename of the scene we are working on and whether we have made any changes to it since the last time we saved
- Fix crash when exiting from fullscreen mode - Fix crash when exiting from fullscreen mode
- Check if we still need to rotate by 90 degrees when exporting from blender - Check if we still need to rotate by 90 degrees when exporting from blender
- Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update - Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update
@ -42,10 +47,7 @@ Todo:
- Color palette, picker and dropper - Color palette, picker and dropper
- Key binding and function to snap editor camera to selected entity - Key binding and function to snap editor camera to selected entity
location location
- Implement resetting complete transform or just rotation, translation
or scale for selected entity
- Key binding and function to orient entity to camera orientation - Key binding and function to orient entity to camera orientation
- Make lights and other entity types pickable
- Mouse warp to opposite side of the window when it reaches bounds - Mouse warp to opposite side of the window when it reaches bounds
- Add other axis combinations like YZ and XY to transform tool - Add other axis combinations like YZ and XY to transform tool
- Transformation space selection for translation, rotation and scale. - Transformation space selection for translation, rotation and scale.
@ -392,4 +394,6 @@ Done:
* Separate entity types in entity hierarchy view by the entity type or use a tree view to show parent/child relation or use different colours for different entity types * Separate entity types in entity hierarchy view by the entity type or use a tree view to show parent/child relation or use different colours for different entity types
* Show archetype name in property inspector for selected entity * Show archetype name in property inspector for selected entity
* Write player camera clear colour when saving scene * Write player camera clear colour when saving scene
* Add uv tiling parameter to materials that can be serialized along with entities * Add uv tiling parameter to materials that can be serialized along with entities
* Implement resetting complete transform or just rotation, translation
or scale for selected entity
Loading…
Cancel
Save