Commit 2ce9a4a4 authored by Brian's avatar Brian

add shader source and fix dynamic memory for cpp

parent 6e67af8b
c:\users\eleph\documents\github\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.pdb
c:\users\eleph\documents\github\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.idb
c:\users\eleph\documents\github\mm_raytracer\visualstudio\mm_raytracer\debug\glad.obj
c:\users\eleph\documents\github\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.obj
c:\users\brian.desktop-db2iif0\desktop\projects\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.pdb
c:\users\brian.desktop-db2iif0\desktop\projects\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.idb
c:\users\brian.desktop-db2iif0\desktop\projects\mm_raytracer\visualstudio\mm_raytracer\debug\glad.obj
c:\users\brian.desktop-db2iif0\desktop\projects\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.obj
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.pdb
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\vc142.idb
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\glad.obj
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.obj
c:\users\eleph\documents\github\mm_raytracer\visualstudio\debug\mm_raytracer.exe
c:\users\eleph\documents\github\mm_raytracer\visualstudio\debug\mm_raytracer.ilk
c:\users\eleph\documents\github\mm_raytracer\visualstudio\debug\mm_raytracer.pdb
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\debug\mm_raytracer.pdb
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\debug\mm_raytracer.exe
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\debug\mm_raytracer.ilk
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\cl.command.1.tlog
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\cl.read.1.tlog
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\cl.write.1.tlog
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\link.command.1.tlog
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\link.read.1.tlog
c:\users\brian\desktop\multimedia\mm_raytracer\visualstudio\mm_raytracer\debug\mm_raytracer.tlog\link.write.1.tlog
 glad.c
glCalls.cpp
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(28,33): error C2440: "=": "void *" kann nicht in "char *" konvertiert werden
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(28,17): message : Konvertierung von "void*" in Zeiger auf nicht-"void" erfordert eine explizite Typumwandlung
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(20,1): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 glCalls.cpp
C:\Users\brian\Desktop\Multimedia\mm_raytracer\src\glCalls.cpp(21,1): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdio.h(208): message : Siehe Deklaration von "fopen"
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(94,68): error C2664: "char *readShaderFromFile(char *)" : Konvertierung von Argument 1 von "const char [19]" in "char *" nicht möglich
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(94,48): message : Bei der Konvertierung von Zeichenfolgenliteral geht der Konstantenqualifizierer verloren (siehe /Zc:strictStrings)
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(15,7): message : Siehe Deklaration von "readShaderFromFile"
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(96,91): error C2664: "GLuint compileShader(GLenum,const char *,char *)" : Konvertierung von Argument 3 von "const char [14]" in "char *" nicht möglich
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(96,76): message : Bei der Konvertierung von Zeichenfolgenliteral geht der Konstantenqualifizierer verloren (siehe /Zc:strictStrings)
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(38,8): message : Siehe Deklaration von "compileShader"
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(110,72): error C2664: "char *readShaderFromFile(char *)" : Konvertierung von Argument 1 von "const char [21]" in "char *" nicht möglich
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(110,50): message : Bei der Konvertierung von Zeichenfolgenliteral geht der Konstantenqualifizierer verloren (siehe /Zc:strictStrings)
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(15,7): message : Siehe Deklaration von "readShaderFromFile"
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(112,99): error C2664: "GLuint compileShader(GLenum,const char *,char *)" : Konvertierung von Argument 3 von "const char [16]" in "char *" nicht möglich
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(112,82): message : Bei der Konvertierung von Zeichenfolgenliteral geht der Konstantenqualifizierer verloren (siehe /Zc:strictStrings)
mm_raytracer.cpp
Code wird generiert...
C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\src\glCalls.cpp(38,8): message : Siehe Deklaration von "compileShader"
B^C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\SRC\GLAD.C
......
B^C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\SRC\GLAD.C
......
B^C:\USERS\BRIAN\DESKTOP\MULTIMEDIA\MM_RAYTRACER\SRC\GLAD.C
......
Binary files a/VisualStudio/mm_raytracer/Debug/mm_raytracer.tlog/link.command.1.tlog and /dev/null differ
Binary files a/VisualStudio/mm_raytracer/Debug/mm_raytracer.tlog/link.read.1.tlog and /dev/null differ
Binary files a/VisualStudio/mm_raytracer/Debug/mm_raytracer.tlog/link.write.1.tlog and /dev/null differ
#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0
Debug|Win32|C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\VisualStudio\|
Debug|Win32|C:\Users\brian\Desktop\Multimedia\mm_raytracer\VisualStudio\|
......@@ -162,6 +162,9 @@
<ClInclude Include="..\..\include\sphere.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\shader\compute.glsl" />
<None Include="..\..\shader\fragment.glsl" />
<None Include="..\..\shader\vertex.glsl" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -19,6 +19,9 @@
<Filter Include="Quelldateien\src">
<UniqueIdentifier>{339611eb-a5b0-49d1-8ad6-d0d5886a9f3d}</UniqueIdentifier>
</Filter>
<Filter Include="shader">
<UniqueIdentifier>{a2620821-36aa-4e9c-8e1d-f8d7ea3f4363}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="mm_raytracer.cpp">
......@@ -47,5 +50,14 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="..\..\shader\compute.glsl">
<Filter>shader</Filter>
</None>
<None Include="..\..\shader\fragment.glsl">
<Filter>shader</Filter>
</None>
<None Include="..\..\shader\vertex.glsl">
<Filter>shader</Filter>
</None>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include <assert.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
void checkError(const char* errorText){
GLenum error = glGetError();
......@@ -13,24 +14,25 @@ void checkError(const char* errorText){
}
char* readShaderFromFile(char* filename) {
FILE *fp;
FILE* fp;
long lSize;
char *buffer;
char* buffer;
fp = fopen ( filename , "rb" );
fp = fopen(filename, "rb");
assert(fp);
fseek( fp , 0L , SEEK_END);
lSize = ftell( fp );
rewind( fp );
fseek(fp, 0L, SEEK_END);
lSize = ftell(fp);
rewind(fp);
/* allocate memory for entire content */
buffer = calloc( 1, lSize + 1 );
//buffer = calloc( 1, lSize + 1 );
buffer = new char[lSize];
if ( !buffer ) fclose(fp), fputs("memory alloc fails", stderr), exit(1);
/* copy the file into the buffer */
if ( 1 != fread( buffer , lSize, 1 , fp) )
fclose(fp), free(buffer), fputs("entire read fails", stderr), exit(1);
fclose(fp), fputs("entire read fails", stderr), exit(1);
return buffer;
}
......@@ -65,14 +67,13 @@ GLuint compileShader(GLenum type, const char* shaderSource, char* shaderTag){
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = new char[25];
char* errorMsg = new char[infoLen];
//get error message
glGetShaderInfoLog(shader, infoLen, NULL, errorMsg);
printf("Error compiling shader (%s): %s\n", shaderTag, errorMsg);
delete(errorMsg);
}
// delete shader object
......@@ -91,9 +92,9 @@ GLboolean init(GLFWwindow* window){
glfwSetWindowUserPointer(window, (void*)userData);
//Create the vertex shader:
char* vertexShaderSource = readShaderFromFile("shader/vertex.glsl");
char* vertexShaderSource = readShaderFromFile((char*)"shader/vertex.glsl");
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource, "Vertex shader");
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource, (char*)"Vertex shader");
delete(vertexShaderSource);
......@@ -106,10 +107,11 @@ GLboolean init(GLFWwindow* window){
delete(computeShaderSource);
*/
//Create the fragment shader:
char* fragmentShaderSource = readShaderFromFile("shader/fragment.glsl");
char* fragmentShaderSource = readShaderFromFile((char*)"shader/fragment.glsl");
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, "Fragment shader");
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, (char*)"Fragment shader");
delete(fragmentShaderSource);
......@@ -155,14 +157,13 @@ GLboolean init(GLFWwindow* window){
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = new char[25];
char* errorMsg = new char[infoLen];
//get error message from program object
glGetProgramInfoLog(programObject, infoLen, NULL, errorMsg);
printf("Error linking program: %s\n", errorMsg);
delete(errorMsg);
}
glDeleteProgram(programObject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment