问题描述
我正在使用Eclipse,MinGW,我已经编译了freeglut和glew,并将他们的库,DLL和头文件复制到正确的位置(MinGW / include / GL,MinGW / lib,Windows / SysWOW64)。我还在MinGW C ++链接器下的Eclipse中连接了库(freeglut64,opengl32,glew32,glu32)。这是我的代码... - CharGame.cpp--
#include< stdlib.h>
#include< stdio.h>
#include< string.h>
#include< GL / glew.h>
#include< GL / freeglut.h>
#includeCharGame.h
#define WINDOW_TITLECharGame
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
无符号FrameCount = 0;
GLuint VertexShaderId,
FragmentShaderId,
ProgramId,
VaoId,
VboId,
ColorBufferId;
int main(int argc,char * argv []){
Initialize(argc,argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
const GLchar * VertexShader =
{
#version 400\\\
\
vec4中的layout(location = 0) in_Cosition; \\\
\
layout(location = 1)in vec4 in_Color; \\\
\
out vec4 ex_Color; \\\
\
void main(void)\\\
\
{\\\
\
gl_Position = in_Position; \\\
\
ex_Color = in_Color; \\\
\
} \\\
};
const GLchar * FragmentShader =
{
#version 400\\\
\
in vec4 ex_Color; \\\
\
out vec4 out_Color; \\\
\
void main(void)\\\
\
{\\\
\
out_Color = ex_Color; \\\
\
} \\\
};
void初始化(int argc,char * argv []){
glutInit(& argc,argv);
glutInitContextVersion(4,0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
glutInitWindowSize(CurrentWidth,CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE);
if(WindowHandle< 1){
fprintf(stderr,Error:Could not create a render window.\\\
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(Resize);
glutDisplayFunc(Render);
glutIdleFunc(Idle);
glutTimerFunc(0,Timer,0);
fprintf(stdout,Info:OpenGL Version:%s\\\
,glGetString(GL_VERSION));
glClearColor(0.0f,0.0f,0.0f,0.0f);
}
void调整大小(int width,int height){
CurrentHeight = height;
CurrentWidth = width;
glViewport(0,0,CurrentWidth,CurrentHeight);
}
void Render(void){
++ FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES,0,3);
glutSwapBuffers();
glutPostRedisplay();
}
void Idle(void){
glutPostRedisplay();
}
void Timer(int value){
if(0!= value){
char * TempString =(char *)malloc(512 + strlen WINDOW_TITLE));
sprintf(TempString,%s:%d Frames Per Second @%d x%d,WINDOW_TITLE,FrameCount * 4,CurrentWidth,CurrentHeight);
glutSetWindowTitle(TempString);
free(TempString);
}
FrameCount = 0;
glutTimerFunc(250,Timer,1);
}
--End CharGame.cpp--
--CharGame.h--
#ifndef CHARGAME_H_
#define CHARGAME_H_
void Initialize(int,char * []);
void InitWindow(int,char * []);
void Resize(int,int);
void Render(void);
void Timer(int);
void Idle(void);
#endif
--End CharGame.h--
我相信我已经做了一切正确,但是Eclipse在VertexShader和FragmentShader上抛出错误TypeGLchar无法解决。我的代码中有错误或错过了一个必要的步骤吗?
这只是扩展了我对另一个答案的评论:
const char * VertexShader =
R(#version 400
layout(location = vec4 in_Position;
layout(location = 1)in vec4 in_Color;
out vec4 ex_Color;
void main(void)
{
gl_Position = in_Position;
ex_Color = in_Color;
}
);
I'm using Eclipse, MinGW, and I have compiled freeglut and glew and copied their libraries, DLLs, and header files into the proper locations (MinGW/include/GL, MinGW/lib, Windows/SysWOW64). I have also linked the libraries (freeglut64, opengl32, glew32, glu32) in Eclipse under the MinGW C++ Linker. Here is my code...
--CharGame.cpp--
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "CharGame.h"
#define WINDOW_TITLE "CharGame"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
unsigned FrameCount = 0;
GLuint VertexShaderId,
FragmentShaderId,
ProgramId,
VaoId,
VboId,
ColorBufferId;
int main(int argc, char* argv[]) {
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
const GLchar* VertexShader =
{
"#version 400\n"\
"layout(location=0) in vec4 in_Position;\n"\
"layout(location=1) in vec4 in_Color;\n"\
"out vec4 ex_Color;\n"\
"void main(void)\n"\
"{\n"\
" gl_Position = in_Position;\n"\
" ex_Color = in_Color;\n"\
"}\n"
};
const GLchar* FragmentShader =
{
"#version 400\n"\
"in vec4 ex_Color;\n"\
"out vec4 out_Color;\n"\
"void main(void)\n"\
"{\n"\
" out_Color = ex_Color;\n"\
"}\n"
};
void Initialize(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE);
if (WindowHandle < 1) {
fprintf(stderr, "Error: Could not create a render window.\n");
exit(EXIT_FAILURE);
}
glutReshapeFunc(Resize);
glutDisplayFunc(Render);
glutIdleFunc(Idle);
glutTimerFunc(0, Timer, 0);
fprintf(stdout, "Info: OpenGL Version: %s\n", glGetString(GL_VERSION));
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void Resize(int width, int height) {
CurrentHeight = height;
CurrentWidth = width;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void Render(void) {
++FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
glutSwapBuffers();
glutPostRedisplay();
}
void Idle(void) {
glutPostRedisplay();
}
void Timer(int value) {
if (0 != value) {
char* TempString = (char*) malloc(512 + strlen(WINDOW_TITLE));
sprintf(TempString, "%s: %d Frames Per Second @ %d x %d", WINDOW_TITLE, FrameCount*4, CurrentWidth, CurrentHeight);
glutSetWindowTitle(TempString);
free(TempString);
}
FrameCount = 0;
glutTimerFunc(250, Timer, 1);
}
--End CharGame.cpp--
--CharGame.h--
#ifndef CHARGAME_H_
#define CHARGAME_H_
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void Resize(int,int);
void Render(void);
void Timer(int);
void Idle(void);
#endif
--End CharGame.h--
I believe I have done everything right, however, Eclipse throws the error "Type 'GLchar' could not be resolved" on VertexShader and FragmentShader. Did I make a mistake in my code or miss a required step?
This is just expanding on my comment on another answer:
const char* VertexShader =
R"(#version 400
layout(location=0) in vec4 in_Position;
layout(location=1) in vec4 in_Color;
out vec4 ex_Color;
void main(void)
{
gl_Position = in_Position;
ex_Color = in_Color;
}
)";
这篇关于键入“GLchar”无法解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!