Commit fa146297 authored by Brian's avatar Brian

change malloc to new and gcalls.c into gcalls.cpp

some "const char" errors occur
parent 792fda12
 mm_raytracer.cpp
mm_raytracer.vcxproj -> C:\Users\eleph\Documents\GitHub\mm_raytracer\VisualStudio\Debug\mm_raytracer.exe
 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.
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\ELEPH\SOURCE\REPOS\MM_RAYTRACER\MM_RAYTRACER\MM_RAYTRACER.CPP
......
B^C:\USERS\ELEPH\DOCUMENTS\GITHUB\MM_RAYTRACER\SRC\GLAD.C
......
B^C:\USERS\ELEPH\DOCUMENTS\GITHUB\MM_RAYTRACER\SRC\GLAD.C
......
#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0
Debug|Win32|C:\Users\eleph\Documents\GitHub\mm_raytracer\VisualStudio\|
Debug|Win32|C:\Users\brian.DESKTOP-DB2IIF0\Desktop\Projects\mm_raytracer\VisualStudio\|
......@@ -152,7 +152,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\glad.c" />
<ClCompile Include="..\..\src\glCalls.c" />
<ClCompile Include="..\..\src\glCalls.cpp" />
<ClCompile Include="mm_raytracer.cpp" />
</ItemGroup>
<ItemGroup>
......
......@@ -27,7 +27,7 @@
<ClCompile Include="..\..\src\glad.c">
<Filter>Quelldateien\src</Filter>
</ClCompile>
<ClCompile Include="..\..\src\glCalls.c">
<ClCompile Include="..\..\src\glCalls.cpp">
<Filter>Quelldateien\src</Filter>
</ClCompile>
</ItemGroup>
......
#ifndef GLCALLS_H
#define GLCALLS_H
#define _USE_MATH_DEFINES
#include "../include/glad/glad.h"
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <math.h>
#define ATTRIB_POSITION 0
#define ATTRIB_COLOR 1
/*
#define Y_ROT_SPEED 10.0
#define X_ROT_SPEED 10.0
*/
typedef struct{
GLuint programObject;
......
#include "../include/glCalls.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void checkError(const char* errorText){
......@@ -66,14 +65,14 @@ GLuint compileShader(GLenum type, const char* shaderSource, char* shaderTag){
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = malloc(sizeof(char) * infoLen);
char* errorMsg = new char[25];
//get error message
glGetShaderInfoLog(shader, infoLen, NULL, errorMsg);
printf("Error compiling shader (%s): %s\n", shaderTag, errorMsg);
free(errorMsg);
delete(errorMsg);
}
// delete shader object
......@@ -88,7 +87,7 @@ GLuint compileShader(GLenum type, const char* shaderSource, char* shaderTag){
GLboolean init(GLFWwindow* window){
//allocate memory for user data
UserData* userData = malloc(sizeof(UserData));
UserData* userData = new UserData;
glfwSetWindowUserPointer(window, (void*)userData);
//Create the vertex shader:
......@@ -96,7 +95,7 @@ GLboolean init(GLFWwindow* window){
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource, "Vertex shader");
free(vertexShaderSource);
delete(vertexShaderSource);
/*
//Create the vertex shader:
......@@ -104,7 +103,7 @@ GLboolean init(GLFWwindow* window){
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, computeShaderSource, "compute shader");
free(computeShaderSource);
delete(computeShaderSource);
*/
//Create the fragment shader:
......@@ -112,7 +111,7 @@ GLboolean init(GLFWwindow* window){
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, "Fragment shader");
free(fragmentShaderSource);
delete(fragmentShaderSource);
// hint to release resources of shader compiler
glReleaseShaderCompiler();
......@@ -156,14 +155,14 @@ GLboolean init(GLFWwindow* window){
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = malloc(sizeof(char) * infoLen);
char* errorMsg = new char[25];
//get error message from program object
glGetProgramInfoLog(programObject, infoLen, NULL, errorMsg);
printf("Error linking program: %s\n", errorMsg);
free(errorMsg);
delete(errorMsg);
}
glDeleteProgram(programObject);
......@@ -241,6 +240,7 @@ void update(GLFWwindow* window)
{
UserData* userData = (UserData*) glfwGetWindowUserPointer(window);
/*
//calculate time delta
double newTime = glfwGetTime();
double timeDelta = newTime - userData->time;
......@@ -251,6 +251,7 @@ void update(GLFWwindow* window)
//update angle y:
//Fmod = float modulo, [0.0, 2pi]
userData->angleY = fmod(userData->angleY + (Y_ROT_SPEED * timeDelta), 2 * M_PI);
*/
// get the window size
int width, height;
......@@ -293,7 +294,7 @@ void teardown(GLFWwindow* window){
glDeleteVertexArrays(1, &(userData->vertexArrayObject));
checkError("glDeleteVertexArrays");
free(userData);
delete(userData);
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
......
#include "../include/glCalls.h"
#include <assert.h>
#include <stdlib.h>
#include <assert.h>
void checkError(const char* errorText){
GLenum error = glGetError();
if(error != GL_NO_ERROR){
printf("GLError: %s - %d\n", errorText, error);
exit(0);
}
}
char* readShaderFromFile(char* filename) {
FILE *fp;
long lSize;
char *buffer;
fp = fopen ( filename , "rb" );
assert(fp);
fseek( fp , 0L , SEEK_END);
lSize = ftell( fp );
rewind( fp );
/* allocate memory for entire content */
buffer = calloc( 1, lSize + 1 );
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);
return buffer;
}
GLuint compileShader(GLenum type, const char* shaderSource, char* shaderTag){
//shader handle
GLuint shader;
//create empty shader object
shader = glCreateShader(type);
if(shader == 0) return 0;
//put source code into empty shader object
glShaderSource(shader, 1, &shaderSource, NULL);
//compile shader
glCompileShader(shader);
//compile status
GLint compiled;
//check compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if( !compiled ){
GLint infoLen = 0;
//get length of error message
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = new char[25];
//get error message
glGetShaderInfoLog(shader, infoLen, NULL, errorMsg);
printf("Error compiling shader (%s): %s\n", shaderTag, errorMsg);
delete(errorMsg);
}
// delete shader object
glDeleteShader(shader);
return GL_FALSE;
}
return shader;
}
GLboolean init(GLFWwindow* window){
//allocate memory for user data
UserData* userData = new UserData;
glfwSetWindowUserPointer(window, (void*)userData);
//Create the vertex shader:
char* vertexShaderSource = readShaderFromFile("shader/vertex.glsl");
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource, "Vertex shader");
delete(vertexShaderSource);
/*
//Create the vertex shader:
char* computeShaderSource = readShaderFromFile("shader/compute.glsl");
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, computeShaderSource, "compute shader");
delete(computeShaderSource);
*/
//Create the fragment shader:
char* fragmentShaderSource = readShaderFromFile("shader/fragment.glsl");
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, "Fragment shader");
delete(fragmentShaderSource);
// hint to release resources of shader compiler
glReleaseShaderCompiler();
//program handle
GLuint programObject;
//create empty program object
programObject = glCreateProgram();
if(programObject == 0) return 0;
// attach shaders to program object
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// link shaders
glLinkProgram(programObject);
checkError("glLinkProgram");
// detach shaders from program object
glDetachShader(programObject, vertexShader);
glDetachShader(programObject, fragmentShader);
// delete shader objects
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
// link status
GLint linked;
// check link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
checkError("glGetProgramiv");
if( !linked ){
GLint infoLen;
//get length of linker error message
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if( infoLen > 1){
char* errorMsg = new char[25];
//get error message from program object
glGetProgramInfoLog(programObject, infoLen, NULL, errorMsg);
printf("Error linking program: %s\n", errorMsg);
delete(errorMsg);
}
glDeleteProgram(programObject);
return GL_FALSE;
}
// use program
glUseProgram(programObject);
checkError("glUseProgram");
// store program object in context
userData->programObject = programObject;
//get uniform locations
userData->angleXLoc = glGetUniformLocation(userData->programObject, "angle_x");
checkError("glGetUniformLocation (angle_x)");
assert(userData->angleYLoc >= 0);
userData->angleYLoc = glGetUniformLocation(userData->programObject, "angle_y");
checkError("glGetUniformLocation (angle_y)");
assert(userData->angleYLoc >= 0);
//initialize the modell
userData->time = glfwGetTime();
userData->angleY = 0.0f;
userData->angleX = 0.0f;
// create and bind dummy vao... it is needed in desktop OpenGL
glGenVertexArrays(1, &(userData->vertexArrayObject));
checkError("glGenVertexArray");
glBindVertexArray(userData->vertexArrayObject);
checkError("glBindVertexArray");
// generate a VBO
glGenBuffers(1, &(userData->vertexBufferObject));
checkError("glGenBuffers");
glBindBuffer(GL_ARRAY_BUFFER, userData->vertexBufferObject);
checkError("glBindBuffer");
//attribute index, component count, normalize, stride, pointer
glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, position));
checkError("glVertexAttribPointer - ATTRIB_POSITION");
//enable vertex attribute
glEnableVertexAttribArray(ATTRIB_POSITION);
checkError("glEnableVertexAttribArray - ATTRIB_POSITION");
//attribute index, component count, normalize, stride, pointer
glVertexAttribPointer(ATTRIB_COLOR, 3, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, color));
checkError("glVertexAttribPointer - ATTRIB_COLOR");
//enable vertex attribute
glEnableVertexAttribArray(ATTRIB_COLOR);
checkError("glEnableVertexAttribArray - ATTRIB_COLOR");
// get the window size
int width, height;
glfwGetFramebufferSize(window, &width, &height);
// set viewport
glViewport(0, 0, width, height);
checkError("glViewport");
// define clear for color buffer with black color
glClearColor(0.2f,0.2f,0.2f,0.0f);
checkError("glClearColor");
return GL_TRUE;
}
void update(GLFWwindow* window)
{
UserData* userData = (UserData*) glfwGetWindowUserPointer(window);
/*
//calculate time delta
double newTime = glfwGetTime();
double timeDelta = newTime - userData->time;
userData->time = newTime;
userData->angleX = fmod(userData->angleX + (X_ROT_SPEED * timeDelta), 2 * M_PI);
//update angle y:
//Fmod = float modulo, [0.0, 2pi]
userData->angleY = fmod(userData->angleY + (Y_ROT_SPEED * timeDelta), 2 * M_PI);
*/
// get the window size
int width, height;
glfwGetFramebufferSize(window, &width, &height);
//update width and height
userData->height = height;
userData->width = width;
/*
// set viewport
glViewport(0, 0, width, height);
checkError("glViewport");
*/
//update uniforms
glUniform1f(userData->angleYLoc, userData->angleY);
checkError("glUniform1f (angleY)");
}
void draw (GLFWwindow* window){
UserData* userData = (UserData*) glfwGetWindowUserPointer(window);
// clear color buffer
glClear(GL_COLOR_BUFFER_BIT);
// draw stuff
// primitive type, start index in array, number of elements to render
glDrawArrays(GL_TRIANGLES, 0, userData->vertexDataCount);
//TODO
glfwSwapBuffers(window);
}
void teardown(GLFWwindow* window){
UserData* userData = (UserData*) glfwGetWindowUserPointer(window);
glDeleteBuffers(1, &(userData->vertexBufferObject));
checkError("glDeleteBuffers");
glDeleteVertexArrays(1, &(userData->vertexArrayObject));
checkError("glDeleteVertexArrays");
delete(userData);
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
}
void error_callback(int error, const char* description){
fprintf(stderr, "Error: %s\n", description);
}
\ No newline at end of file
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