-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 3 Part 1: Model Loading #90
Open
DigitalBox98
wants to merge
10
commits into
opentk:master
Choose a base branch
from
DigitalBox98:chapter3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f6bb7cc
Chapter 3 Part 1: Model Loading
camelotinsider 744eb5a
Model addition
camelotinsider 22ab620
Model as binary
camelotinsider 7005f94
Keep Handle in Shader
camelotinsider bce9c2d
Fix Handle properties in Texture
camelotinsider cb0874a
Readonly fix
camelotinsider e19e7c2
Fix Texture window example
camelotinsider 6785695
Cleanup
camelotinsider 2d95938
Code review
camelotinsider 59e8a0b
Add backpack.obj again
camelotinsider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,8 @@ public class Texture | |
public string type; | ||
public string path; | ||
|
||
public static Texture LoadFromFile(string path, string directory, string type) | ||
public static Texture LoadFromFile(string filename, string type = "texture_diffuse") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally avoid default arguments in opentk code. Also I don't think this field is a good idea, and if we where going to do it I would rather this be an enum rather than a string. |
||
{ | ||
string filename = new string(path); | ||
filename = directory + '/' + filename; | ||
|
||
// Generate handle ID | ||
int ID = GL.GenTexture(); | ||
|
@@ -29,7 +27,7 @@ public static Texture LoadFromFile(string path, string directory, string type) | |
// OpenGL has it's texture origin in the lower left corner instead of the top left corner, | ||
// so we tell StbImageSharp to flip the image when loading. | ||
// StbImage.stbi_set_flip_vertically_on_load(1); | ||
|
||
// Here we open a stream to the file and pass it to StbImageSharp to load. | ||
using (Stream stream = File.OpenRead(filename)) | ||
{ | ||
|
@@ -48,7 +46,7 @@ public static Texture LoadFromFile(string path, string directory, string type) | |
// And finally, the actual pixels. | ||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Data); | ||
} | ||
|
||
// Now that our texture is loaded, we can set a few settings to affect how the image appears on rendering. | ||
|
||
// First, we set the min and mag filter. These are used for when the texture is scaled down and up, respectively. | ||
|
@@ -73,10 +71,9 @@ public static Texture LoadFromFile(string path, string directory, string type) | |
// Here is an example of mips in action https://en.wikipedia.org/wiki/File:Mipmap_Aliasing_Comparison.png | ||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); | ||
|
||
return new Texture(ID, path, type); | ||
return new Texture(ID, filename, type); | ||
} | ||
|
||
|
||
public Texture(int glHandle, string path, string type) | ||
{ | ||
this.ID = glHandle; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
Path.Combine(directory, str.FilePath)
.