(OpenGL)0xC0000005: 执行位置 0x0000000000000000 时发生访问冲突,运行glBindBuffer函数时崩溃。

1.运行一个OpenGL/CUDA相结合的样例程序,main.cpp编译成功。运行可执行文件时图形界面无法成功运行,调试过程中显示在glBindBuffer函数处程序报错。

2.main.cpp代码:

#include "kernel.h"
#include <stdio.h>
#include <stdlib.h>

#ifdef _WIN32
#define WINDOWS_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif

#ifdef __APPLE__
#include<GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/freeglut.h>
#endif

#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#include "interactions.h"

//texture and pixel objects
GLuint pbo = 0;//OpenGL pixel buffer object
GLuint tex = 0;//OpenGL texture object
struct cudaGraphicsResource *cuda_pbo_resource;

void render()
{
    uchar4 *d_out = 0;
    cudaGraphicsMapResources(1, &cuda_pbo_resource, 0);
    cudaGraphicsResourceGetMappedPointer((void**)&d_out, NULL, cuda_pbo_resource);
    kernelLauncher(d_out,W, H, loc);
    cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0);
}

void drawTexture()
{
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA,GL_UNSIGNED_BYTE,NULL);
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex2f(0, 0);
    glTexCoord2f(0.0f, 1.0f); glVertex2f(0, H);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(W, H);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(W, 0);
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

void display()
{
    render();
    drawTexture();
    glutSwapBuffers();
}

void initGLUT(int *argc, char** argv)
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(W,H);
    glutCreateWindow(TITLE_STRING);
#ifdef __APPLE__
    glewInit();
#endif
}

void initPixelBuffer()
{
    GLuint pbo = 0;
    glGenBuffers(1, &pbo); 
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
    glBufferData(GL_PIXEL_UNPACK_BUFFER, 4 * W * H * sizeof(GLubyte), 0, GL_STREAM_DRAW);

    GLuint tex = 0;
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    cudaGraphicsGLRegisterBuffer(&cuda_pbo_resource, pbo, cudaGraphicsMapFlagsWriteDiscard);
}

void exitfunc()
{
    if (pbo)
    {
        cudaGraphicsUnregisterResource(cuda_pbo_resource);
        glDeleteBuffers(1, &pbo);
        glDeleteTextures(1, &tex);
    }
}
int main(int argc,char** argv)
{
    printInstructions();
    initGLUT(&argc, argv);
    gluOrtho2D(0, W, H, 0);
    glutKeyboardFunc(keyboard);
    glutSpecialFunc(handleSpecialKeypress);
    glutPassiveMotionFunc(mouseMove);
    glutMotionFunc(mouseDrag);
    glutDisplayFunc(display);
    initPixelBuffer();
    glutMainLoop();
    atexit(exitfunc);
    return 0;
}

3.报错信息:0x0000000000000000 处(位于 dist_2d_cuda.exe 中)引发的异常: 0xC0000005: 执行位置 0x0000000000000000 时发生访问冲突。

请问具体是什么问题呢,向各位求助~

1个回答

0x0000000000000000
这个明显是你访问了野指针了。具体要你调试下才知道。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
0x00000000 处的第一机会异常(在 LOAD_WIZARD.exe 中): 0xC0000005: 执行位置 0x00000000 时发生访问冲突

VS2012编译能够成功,但是在调用的时候出现了上述问题问题,请各位指点。运行的时候一直到printf那里都是没有问题的。 调用的代码如下 ``` #include "stdafx.h" #include <stdio.h> #include <windows.h> typedef void(*MAINFUNCTION)(int Type, const char *HandleNum, const char *MiddleNum, const char *PoleNum, const char *BladeNum); int _tmain(int argc, _TCHAR* argv[]) { HMODULE hModule1 = GetModuleHandle(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\NX10_NXOpenCPP_Wizard1.dll"); if (NULL == hModule1) { hModule1 = LoadLibraryEx(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\tool_assenbal_external.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH); //hModule1 = LoadLibrary(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\NX10_NXOpenCPP_Wizard1.dll"); } MAINFUNCTION Mainfunction = (MAINFUNCTION)GetProcAddress(hModule1, "Mainfunction"); const char *HandleNum2 = "BT40-ER32-70"; const char *MiddleNum2 = "ER32-12"; const char *PoleNum2 = "D10"; const char *BladeNum2 = ""; printf("测试代码1!"); Mainfunction(2, HandleNum2, MiddleNum2, PoleNum2, BladeNum2); FreeLibrary(hModule1); getchar(); return 0; } ``` 函数体如下 ``` extern "C" DllExport void Mainfunction(int Type, const char *HandleNum, const char *MiddleNum, const char *PoleNum, const char *BladeNum) { //以下为用户代码 Handle = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀柄库\\"; Middle = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\夹套库\\"; Pole = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀杆库\\"; Blade = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀片库\\"; HandleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\HandleBase.dat"; MiddleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\MiddleBase.dat"; PoleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\PoleBase.dat"; CompletePath = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\整刀库\\"; if( UF_CALL(UF_initialize()) ) { /* Failed to initialize */ return ; } printf("开始导入!\n"); //新建一个prt tag_t PartTAG = NULL_TAG; UF_CALL(UF_PART_new("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\Temp\\Test.prt", UF_PART_METRIC, &PartTAG)); char ToolPath[255]; if (1 == Type) { ImportHandle(HandleNum); sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", BladeNum, ".prt"); } else if (2 == Type) { ImportHandle(HandleNum); ImportMiddle(MiddleNum); ImportPole(PoleNum); sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", MiddleNum, "+", PoleNum,".prt"); } else { ImportHandle(HandleNum); ImportMiddle(MiddleNum); ImportPole(PoleNum); sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", MiddleNum, "+", PoleNum, BladeNum, ".prt"); } printf("导入完成!\n"); UF_CALL(UF_PART_save_as(ToolPath)); UF_CALL(UF_PART_close(PartTAG, 0, 1)); UF_CALL(UF_terminate()); return ; } ```

0xC0000005: 读取位置 0x34432f38 时发生访问冲突

// 王天浩1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> using namespace std; const int maxnum = 100; const int maxint = 999999; void Dijkstra(int n, int v, int *dist, int *prev, int c[maxnum][maxnum]) { bool s[maxnum]; // 判断是否已存入该点到S集合中 for(int i=1; i<=n; ++i) { dist[i] = c[v][i]; s[i] = 0; // 初始都未用过该点 if(dist[i] == maxint) prev[i] = 0; else prev[i] = v; } dist[v] = 0; s[v] = 1; // 依次将未放入S集合的结点中,取dist[]最小值的结点,放入结合S中 // 一旦S包含了所有V中顶点,dist就记录了从源点到所有其他顶点之间的最短路径长度 for(int i=2; i<=n; ++i) { int tmp = maxint; int u = v; // 找出当前未使用的点j的dist[j]最小值 for(int j=1; j<=n; ++j) if((!s[j]) && dist[j]<tmp) { u = j; // u保存当前邻接点中距离最小的点的号码 tmp = dist[j]; } s[u] = 1; // 表示u点已存入S集合中 // 更新dist for(int j=1; j<=n; ++j) if((!s[j]) && c[u][j]<maxint) { int newdist = dist[u] + c[u][j]; if(newdist < dist[j]) { dist[j] = newdist; prev[j] = u; } } } } void searchPath(int *prev,int v, int u) { int que[maxnum]; int tot = 1; que[tot] = u; tot++; int tmp = prev[u]; while(tmp != v) { que[tot] = tmp; tot++; tmp = prev[tmp]; } que[tot] = v; for(int i=tot; i>=1; --i) if(i != 1) cout << que[i] << " -> "; else cout << que[i] << endl; } int main() { freopen("input.txt", "r", stdin); // 各数组都从下标1开始 int dist[maxnum]; // 表示当前点到源点的最短路径长度 int prev[maxnum]; // 记录当前点的前一个结点 int c[maxnum][maxnum]; // 记录图的两点间路径长度 int n, line; // 图的结点数和路径数 // 输入结点数 cin >> n; // 输入路径数 cin >> line; int p, q, len; // 输入p, q两点及其路径长度 // 初始化c[][]为maxint for(int i=1; i<=n; ++i) for(int j=1; j<=n; ++j) c[i][j] = maxint; for(int i=1; i<=line; ++i) { cin >> p >> q >> len; if(len < c[p][q]) // 有重边 { c[p][q] = len; // p指向q c[q][p] = len; // q指向p,这样表示无向图 } } for(int i=1; i<=n; ++i) dist[i] = maxint; for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) printf("%8d", c[i][j]); printf("\n"); } Dijkstra(n, 1, dist, prev, c); // 最短路径长度 cout << "源点到最后一个顶点的最短路径长度: " << dist[n] << endl; // 路径 cout << "源点到最后一个顶点的路径为: "; searchPath(prev, 1, n); }

0x0001af3a 处有未经处理的异常: 0xC0000005: Access violation

opengl程序在自己的电脑vs2010上面运行出错,在别人电脑没问题,重新配置了n次glew都不行,每次都弹出:0x0001af3a 处有未经处理的异常: 0xC0000005: Access violation,并且自动打开gs_support.c跳到 cookie = systime.ft_struct.dwLowDateTime;!![CSDN移动问答][1] [1]: http://zhidao.baidu.com/question/936332428647718532.html?quesup2&oldq=1

用完cmake后原本可以运行的opengl程序报错“(ig9icd32.dll)处引发的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突。”

环境:win10 64bit 软件:vs 2017 cmake-3.16.0 每次使用cmake编译文件,按[这个](https://blog.csdn.net/sda42342342423/article/details/78218920 "") 一步步配置openmesh,打开gui一些参数的配置如下: ![这是我在编译前的选择](https://img-ask.csdn.net/upload/201910/13/1570940862_404209.png) 点configure还一切正常,不过有一片红的区域的checkbox。完事后点generate就报错了: ![图片说明](https://img-ask.csdn.net/upload/201910/13/1570941123_218651.png) 怀着不幸的预感打开vs,新建控制台应用程序,按网上继续配置参数。 一debug果然报错: ``` E0035 #error 指令: "You have to define _USE_MATH_DEFINES in the compiler settings!" 大作业 F:\download\OpenMesh-8.0\src\OpenMesh\Core\System\compiler.hh 110 C1189 #error: "You have to define _USE_MATH_DEFINES in the compiler settings!" 大作业 f:\download\openmesh-8.0\src\openmesh\core\system\compiler.hh 110 ``` 更不幸的是原本可以运行的opengl也不能运行了: ``` 0x0319C5D5 (ig9icd32.dll)处(位于 exp1_BreAndDDA.exe 中)引发的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突。 ``` 救救孩子,不想再重装系统了/泪目 谢谢大佬们

未处理的异常 0xc0000005 ,读取位置0x00000000时发生访问冲突。如何解决

调试程序时发生错误,通过函数调用堆展定位到的语句:BYTE currentElement = bitmap[current.x][ current.y];并且 指针定义如下:Point current; BYTE ** bitmap; // 图像指针 point定义如下: class Point { public: Point(); Point(int a, int b); virtual ~Point(); public: int x; int y; void translate(int dx, int dy); void set(int a, int b); Point getCenter(Point p1, Point p2); bool equals(Point compare); int distanceOf(Point other); }; 不知道哪里出现了空指针之类的内存错误,各位大侠看看怎么修改。

我的代码编译没有问题,但运行时出现访问冲突:

0x00421ab3 处未处理的异常: 0xC0000005: 读取位置 0xfdfdfe05 时发生访问冲突 我检查代码发现他是执行到 p= "^(@|$)"; CRegexpT<char> reg( p,IGNORECASE ); MatchResult match_ret = reg.Match( Buf_Line); 发生的,调用堆栈第一行是 > Test.exe!CBuilderT<char>::Clear() 行1658 + 0x3e 字节 C++ 第二行是 > Test.exe!CBuilderT<char>::~CBuilderT<char>() 行1532 C++ 请问大神这样的错误怎么改啊,,,小弟菜鸟一个,,请大神们指点,,急急急~~~~

openGL 程序编译报错,求大神

0x69193340 (nvoglv32.dll)处(位于 OpenGL_Shader.exe 中)引发的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突。 感觉是加载shader的时候报错

代码正常运行一会后出现 0xC0000005: 读取位置 0x00000010 时发生访问冲突

#include <gl\glut.h> #include<iostream> #include<fstream> #include<sstream> #include<stdio.h> #include<stdlib.h> #include<math.h> using namespace std; typedef struct V { GLdouble x; GLdouble y; GLdouble z; GLdouble X; GLdouble Y; GLdouble Z; GLdouble XN; GLdouble YN; GLdouble ZN; }V;//记录每个顶点窗口坐标、三维坐标以及法向量 V *vertex; int v_num[2]={0,0}; //记录点的数量 int vn_num[2]={0,0};//记录法线的数量 int f_num[2]={0,0}; //记录面的数量 GLdouble **vArr; //存放点的二维数组 GLdouble **vnArr;//存放法线的二维数组 int **fvArr; //存放面顶点的二维数组 int **fnArr; //存放面法线的二维数组 char s1[100];//读取行的数组 GLfloat f2,f3,f4;//读取每行内容的变量 int a=0; char showv[25]=""; char showf[25]=""; char space[5]=" "; char showv1[25]=""; char showvn[25]=""; char vx[25]=""; char vy[25]=""; char vz[25]=""; char vnx[25]=""; char vny[25]=""; char vnz[25]="";//输出字符组 const int SIZE=256; float movex=0; float movey=0; float len=4; int x=0,y=0,z=0; int xRange=0; int yRange=0; //运动变量 GLfloat LightAmbient[]= { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat LightDiffuse[]= { 1.0f, 1.0f, 8.0f, 10.0f }; GLfloat LightPosition[]= { 1.0f, 1.0f, 1.0f, 1.0f }; //灯光属性 int startx; int starty;//鼠标点击坐标记录 int getLineNum(string addrstr)//读取文件的顶点数和面数 { v_num[a]=0; vn_num[a]=0; f_num[a]=0; ifstream infile(addrstr.c_str()); char sline[100]; while(infile.getline(sline,100)) { if(sline[0]=='v') { if(sline[1]=='n') vn_num[a]++; else v_num[a]++; } else if (sline[0]=='f') f_num[a]++; } itoa(v_num[a],showv,10); itoa(f_num[a],showf,10); return 0; } int readfile(string addrstr) //将文件内容读到数组中去 { vertex=new V[v_num[a]]; vArr=new GLdouble*[v_num[a]]; for (int i=0;i<v_num[a];i++) { vArr[i]=new GLdouble[3]; } vnArr=new GLdouble*[vn_num[a]]; for (int i=0;i<vn_num[a];i++) { vnArr[i]=new GLdouble[3]; } fvArr=new int*[f_num[a]]; fnArr=new int*[f_num[a]]; for (int i=0;i<f_num[a];i++) { fvArr[i]=new int[3]; fnArr[i]=new int[3]; } ifstream infile(addrstr.c_str()); int ii=0,jj=0,kk=0; char sline[100]; while(infile.getline(sline,100)) { if(sline[0]=='v') { if(sline[1]=='n')//vn { istringstream sin(sline); sin>>s1>>f2>>f3>>f4; vnArr[ii][0]=f2; vnArr[ii][1]=f3; vnArr[ii][2]=f4; vertex[ii].XN=f2; vertex[ii].YN=f3; vertex[ii].ZN=f4; ii++; } else//v { istringstream sin(sline); sin>>s1>>f2>>f3>>f4; vArr[jj][0]=f2; vArr[jj][1]=f3; vArr[jj][2]=f4; vertex[jj].X=f2; vertex[jj].Y=f3; vertex[jj].Z=f4; jj++; } } if (sline[0]=='f') //读取面 { istringstream in(sline); GLfloat a; in>>s1;//去掉前缀f int i,k; for(i=0;i<3;i++) { in>>s1; //取得顶点索引和法线索引 a=0; for(k=0;s1[k]!='/';k++) { a=a*10+(s1[k]-48); } fvArr[kk][i]=a; a=0; for(k=k+2;s1[k];k++) { a=a*10+(s1[k]-48);; } fnArr[kk][i]=a; } kk++; } } return 0; } void drawbunny() { glBegin(GL_TRIANGLES); for (int i=0;i<f_num[a];i++) { glNormal3f(vnArr[fnArr[i][0]-1][0], vnArr[fnArr[i][0]-1][1], vnArr[fnArr[i][0]-1][2]); glVertex3f(vArr[fvArr[i][0]-1][0], vArr[fvArr[i][0]-1][1], vArr[fvArr[i][0]-1][2]); glNormal3f(vnArr[fnArr[i][1]-1][0], vnArr[fnArr[i][1]-1][1], vnArr[fnArr[i][1]-1][2]); glVertex3f(vArr[fvArr[i][1]-1][0], vArr[fvArr[i][1]-1][1], vArr[fvArr[i][1]-1][2]); glNormal3f(vnArr[fnArr[i][2]-1][0], vnArr[fnArr[i][2]-1][1], vnArr[fnArr[i][2]-1][2]); glVertex3f(vArr[fvArr[i][2]-1][0], vArr[fvArr[i][2]-1][1], vArr[fvArr[i][2]-1][2]); } glEnd(); GLuint base;/*显示顶点数,面数,以及鼠标点击顶点坐标,顶点法向量*/ base=glGenLists(256); for(int i=0;i<256;++i) { glNewList(base+i,GL_COMPILE); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,i); glEndList(); } glColor3f(1.0,1.0,1.0); glRasterPos2f(0.0,-0.1); glListBase(base); glCallLists((GLint)strlen("V"),GL_UNSIGNED_BYTE,"V"); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(showv),GL_UNSIGNED_BYTE,showv); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen("F"),GL_UNSIGNED_BYTE,"F"); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(showf),GL_UNSIGNED_BYTE,showf); glRasterPos2f(-0.2,-0.2); glCallLists((GLint)strlen("v"),GL_UNSIGNED_BYTE,"v"); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vx),GL_UNSIGNED_BYTE,vx); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vy),GL_UNSIGNED_BYTE,vy); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vz),GL_UNSIGNED_BYTE,vz); glRasterPos2f(-0.2,-0.15); glCallLists((GLint)strlen("vn"),GL_UNSIGNED_BYTE,"vn"); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vnx),GL_UNSIGNED_BYTE,vnx); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vny),GL_UNSIGNED_BYTE,vny); glCallLists((GLint)strlen(space),GL_UNSIGNED_BYTE,space); glCallLists((GLint)strlen(vnz),GL_UNSIGNED_BYTE,vnz); glFlush(); glutSwapBuffers(); } void myDisplay() { } void IdleDisplay() { glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // 设置环境光 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // 设置漫射光 glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // 设置光源位置 glEnable(GL_LIGHT1); glClearColor(0.0, 0.0, 0.0, 0.0); glViewport(0,0,800,800); GLint viewport[4]; glGetIntegerv( GL_VIEWPORT , viewport ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -10, 10); GLdouble projectionMatrix[16]; glGetDoublev( GL_PROJECTION_MATRIX , projectionMatrix ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(movex,movey,0); glScalef(len,len,len); glRotatef(xRange, 1, 0, 0); glRotatef(yRange, 0, 1, 0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1.0,0.0,0.0); GLdouble modelMatrix[16]; glGetDoublev( GL_MODELVIEW_MATRIX , modelMatrix ); for(int i=0;i<v_num[a];i++) gluProject(vertex[i].X,vertex[i].Y,vertex[i].Z,modelMatrix,projectionMatrix,viewport,&vertex[i].x,&vertex[i].y,&vertex[i].z);//计算每个顶点的窗口坐标 drawbunny(); } //控制 void moveright() { movex+=0.2; if (movex>5.0) movex=0.0; glutPostRedisplay(); } void moveleft() { movex-=0.2; if (movex<-5.0) movex=0.0; glutPostRedisplay(); } void moveup() { movey+=0.2; if (movey>5.0) movey=0.0; glutPostRedisplay(); } void movedown() { movey-=0.2; if (movey<-5.0) movey=0.0; glutPostRedisplay(); } void shrink() { len-=0.1; if(len<-10) len=-10; glutPostRedisplay(); } void zoom() { len+=0.1; if(len>10) len=10; glutPostRedisplay(); } void specialKeyFunc(int key,int x,int y) { switch(key) { case GLUT_KEY_RIGHT: moveright(); break; case GLUT_KEY_LEFT: moveleft(); break; case GLUT_KEY_DOWN: movedown(); break; case GLUT_KEY_UP: moveup(); break; case GLUT_KEY_F1: zoom(); break; case GLUT_KEY_F2: shrink(); break; default: break; } } void processmenu(int value) { if(value==1) { a=0; getLineNum("bunny.obj"); readfile("bunny.obj"); glutIdleFunc(&IdleDisplay); } if(value==2) { a=1; getLineNum("mycube.obj"); readfile("mycube.obj"); glutIdleFunc(&IdleDisplay); } } void mouse(int button,int state,int x,int y) { if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; if(state==GLUT_DOWN) startx=x,starty=y; GLdouble temp; GLdouble min=100000; for(int i=0;i<v_num[a];i++) { if(vertex[i].x>x-5&&vertex[i].x<x+5&&vertex[i].y>(800-y)-5&&vertex[i].y<800-y+5)//顶点的窗口坐标在鼠标点击范围内 { temp=sqrt(pow(x-vertex[i].x,2)+pow((800-y)-vertex[i].y,2)); if(temp<min)//取距离鼠标点击位置最近的顶点 min=temp; } } int flag=0; GLdouble v[2][4]; GLdouble vn[2][4]; GLdouble zmin; for(int i=0;i<v_num[a];i++) if(sqrt(pow(x-vertex[i].x,2)+pow((800-y)-vertex[i].y,2))==min)//根据获得的最小值依次查询相应顶点 { if(flag==0) { flag++; v[0][0]=vertex[i].X; v[0][1]=vertex[i].Y; v[0][2]=vertex[i].Z; v[0][3]=1; vn[0][0]=vertex[i].XN; vn[0][1]=vertex[i].YN; vn[0][2]=vertex[i].ZN; zmin=vertex[i].z; continue; } if(flag==1)//避免两点恰好重合的情况,如果两点恰好重合,取前点 { v[1][0]=vertex[i].X; v[1][1]=vertex[i].Y; v[1][2]=vertex[i].Z; v[1][3]=1; vn[1][0]=vertex[i].XN; vn[1][1]=vertex[i].YN; vn[1][2]=vertex[i].ZN; if(vertex[i].z>zmin) { v[1][3]=1; v[0][3]=0; } else { v[0][3]=1; v[1][3]=0; } } } if(v[0][3]==1) { sprintf(vx,"%lf",v[0][0]); sprintf(vy,"%lf",v[0][1]); sprintf(vz,"%lf",v[0][2]); sprintf(vnx,"%lf",vn[0][0]); sprintf(vny,"%lf",vn[0][1]); sprintf(vnz,"%lf",vn[0][2]); } if(v[1][3]==1) { sprintf(vx,"%lf",v[1][0]); sprintf(vy,"%lf",v[1][1]); sprintf(vz,"%lf",v[1][2]); sprintf(vnx,"%lf",vn[1][0]); sprintf(vny,"%lf",vn[1][1]); sprintf(vnz,"%lf",vn[1][2]); } glutPostRedisplay(); } void onMouseMove(int x,int y) { xRange += 3.14159265 * (y - starty) / 5; if(xRange >= 360 || xRange <= -360) xRange = 0; yRange += 3.14159265 * (x - startx) / 5; if(yRange >= 360 || yRange <= -360) yRange = 0; startx = x; //把此时的鼠标坐标作为旧值,为下一次计算增量做准备 starty = y; } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowPosition(100, 100); glutInitWindowSize(800, 800); glutCreateWindow("OBJ"); int id=glutCreateMenu(processmenu); glutAddMenuEntry("model1",1); glutAddMenuEntry("model2",2); glutAttachMenu(GLUT_RIGHT_BUTTON); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glutDisplayFunc(&myDisplay); glutSpecialFunc(specialKeyFunc); glutMouseFunc(mouse); glutMotionFunc(onMouseMove); glutMainLoop(); return 0; }

OpenGL的glClear()在Windows 64中导致访问冲突(0xc0000005)

<div class="post-text" itemprop="text"> <p>Take a look at this super-simple small test-case OpenGL program written in Go:</p> <pre><code>package main import ( "runtime" "./glfw" gl "github.com/chsc/gogl/gl21" ) func onExit (err error) { glfw.Terminate() if err != nil { panic(err) } } func main () { runtime.LockOSThread() err := glfw.Init() if err != nil { panic(err) } err = glfw.OpenWindow(1280, 720, 0, 0, 0, 0, 0, 0, glfw.Windowed) if err != nil { onExit(err) } err = gl.Init() if err != nil || gl.GetError() != 0 { onExit(err) } for glfw.WindowParam(glfw.Opened) == 1 { gl.Viewport(0, 0, 1280, 720) gl.ClearColor(1, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT) // THE CRASH gl.Begin(gl.TRIANGLES) gl.Color3f(1, 0, 0) gl.Vertex3f(-1, -1, 0) gl.Color3f(0, 1, 0) gl.Vertex3f(0, 1, 0) gl.Color3f(0, 0, 1) gl.Vertex3f(1, -1, 0) gl.End() glfw.SwapBuffers() if glfw.Key(glfw.KeyEsc) == 1 { glfw.CloseWindow() } } onExit(nil) } </code></pre> <p>This builds fine under Windows 7 64-bit with Go 1.0.1 64-bit.</p> <p>It also <em>works fine</em> (OpenGL draws a single rainbow-colored 2D triangle until the Window is closed) <strong>IF</strong> you take out (or comment-out) the <strong>gl.Clear(gl.COLOR_BUFFER_BIT)</strong> line.</p> <p>As soon as gl.Clear is called however (no matter what arguments are passed), it crashes, Windows informs me that "glfw-win.exe has stopped working..." and the Windows Event Viewer has the following error log for me:</p> <pre><code>Faulting application name: glfw-win.exe, version: 0.0.0.0, time stamp: 0x4f9f5ec5 Faulting module name: glfw-win.exe, version: 0.0.0.0, time stamp: 0x4f9f5ec5 Exception code: 0xc0000005 Fault offset: 0x0000000000012883 Faulting process id: 0xd4c Faulting application start time: 0x01cd274e4c69a3d3 Faulting application path: C:\mytmp\glfw-win\glfw-win.exe Faulting module path: C:\mytmp\glfw-win\glfw-win.exe Report Id: 8a5bacc0-9341-11e1-911a-d067e544ad7f </code></pre> <p>Now, a couple of noteworthy points...</p> <ol> <li><p>The <strong>glfw</strong> package is simply a custom package exposing the exact same API as github.com/jteeuwen/glfw but internally using LoadLibrary/GetProcAddress for using glfw.dll rather than compile-time CGO/GCC/LD linking -- since the latter cannot be made to work in 64-bit Windows sadly, not sure whether mingw64 or gcc or cgo is to blame. With LoadLibrary/GetProcAddress calling my custom 64-bit build of glfw.dll is working mighty fine. Clearly the issue here is with a call to the gl package, not glfw.</p></li> <li><p>The <strong>gl</strong> package is indeed simply <a href="https://github.com/chsc/gogl/blob/master/gl21/gl21.go" rel="nofollow">this one</a>, unmodified. I experimented with a few LDFLAGS modifications such as -m64 -lmingw32 -Wl,/windows/opengl32.dll etc. but no difference, the original works just as fine as the modified ones as long as gl.Clear() is not called, so I reverted back to the original. Of course later on I'll move on to OpenGL 4.2.</p></li> <li><p>Using Process Explorer, I can see my process is 64-bit and all loaded DLLs are 64-bit images too (including opengl32.dll and glfw.dll).</p></li> <li><p>"could it be that the gl21 package could not obtain a valid address for the glClear() function exported by opengl32.dll?" -- unlikely: according to <a href="https://github.com/chsc/gogl/blob/master/gl21/gl21.go#L2926" rel="nofollow">line 2926</a>, my call to gl.Init() would fail if this were the case.</p></li> <li><p>GPU driver issues? Even more unlikely. The very newest official nVidia Quadro 5010M driver 296.35 is installed. Also tried the "performance driver" but seems to be exactly the same driver anyway. Full OpenGL 4.2 support according to nVidia Control Panel (although opengl32.dll is dated 2009 -- anyway, plenty for 2.1 I'm currently targeting). Plus, the OpenGL shaders in "Geeks3D GPU Caps Viewer" and "Shader Toy Mark" run, as does the GLFW example program particles.exe -- all of them use glClear() as well.</p></li> <li><p>Exact same issue happens when using gl42 instead of gl21, so that's not the cause either.</p></li> </ol> <p>Do note how all other gl.SomeExportedFunc() calls do not crash in this example...</p> <p>What to do, how to proceed?</p> <p>I could live with this if this only happens with gl.Clear() and no other funcs ever -- I'm only ever rendering full-screen quads with custom content anyway -- but I'm fairly early in testing Win64 here (got a lot of gl42 code working just fine under Linux64, now about to "port" to Win64) and I fear that additional further calls later on will expose the same problem so I'm reporting this now. I will soon find out which other calls are affected by this.</p> </div>

Microsoft C++ 异常: cv::Exception,位于内存位置 0x000000351C0FF5C0 处。

#include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat image = imread("‪C:\\Users\\13215\\Desktop\test\\test\\test\\Lena.jpg"); //存放自己图像的路径 imshow("显示图像", image); waitKey(0); return 0; } 0x00007FFBBAB9A388 处(位于 test.exe 中)引发的异常: Microsoft C++ 异常: cv::Exception,位于内存位置 0x000000351C0FF5C0 处。 0x00007FFBBAB9A388 处(位于 test.exe 中)有未经处理的异常: Microsoft C++ 异常: cv::Exception,位于内存位置 0x000000351C0FF5C0 处。 SRCSRV: 模块“E:\opencv\build\x64\vc15\bin\opencv_world410d.dll”不包含源服务器信息。 SRCSRV: 模块“E:\opencv\build\x64\vc15\bin\opencv_world410d.dll”不包含源服务器信息。 SRCSRV: 模块“E:\opencv\build\x64\vc15\bin\opencv_world410d.dll”不包含源服务器信息。

xcode OpenGL输出一个窗口

具体错误信息: Starting GLFW context, OpenGL 3.3 2017-03-31 11:00:23.247187+0800 opengl[6941:354760] [General] ERROR: Setting <GLFWContentView: 0x100519d60> as the first responder for window <GLFWWindow: 0x10030e700>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil. ( 0 AppKit 0x00007fff957aea3f -[NSWindow _validateFirstResponder:] + 557 1 AppKit 0x00007fff94f29b1c -[NSWindow _setFirstResponder:] + 31 2 AppKit 0x00007fff94fd1d9e -[NSWindow _realMakeFirstResponder:] + 406 3 AppKit 0x00007fff94fd1bb4 -[NSWindow makeFirstResponder:] + 123 4 libglfw.3.dylib 0x00000001000b9895 _glfwPlatformCreateWindow + 631 5 libglfw.3.dylib 0x00000001000b5430 glfwCreateWindow + 487 6 opengl 0x0000000100000fdf main + 159 7 libdyld.dylib 0x00007fffacb7d235 start + 1 8 ??? 0x0000000000000001 0x0 + 1 ) Failed to create GLFW window Program ended with exit code: 255 代码如下 #include <iostream> // GLEW #define GLEW_STATIC #include <glew.h> // GLFW #include <glfw3.h> // Window dimensions const GLuint WIDTH = 800, HEIGHT = 600; // The MAIN function, from here we start the application and run the game loop int main() { std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl; // Init GLFW glfwInit(); // Set all the required options for GLFW glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Create a GLFWwindow object that we can use for GLFW's functions GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr); if (window == nullptr) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } }

如何安装opengl使其运行

<div class="post-text" itemprop="text"> <p>I am trying following simple code to create a GUI using <a href="https://github.com/fyne-io/fyne" rel="nofollow noreferrer">Fyne</a> package: </p> <pre><code>// from: https://github.com/fyne-io/fyne package main import ( "fyne.io/fyne/widget" "fyne.io/fyne/app" ) func main() { app := app.New() w := app.NewWindow("Hello") w.SetContent(widget.NewVBox( widget.NewLabel("Hello Fyne!"), widget.NewButton("Quit", func() { app.Quit() }), )) w.ShowAndRun() } </code></pre> <p>It compiles and builds executable file without any error or even warning, but on trying to run it gives following error:</p> <pre><code>I:\&gt;rnfynetest 2019/08/25 12:37:18 Fyne error: failed to initialise OpenGL 2019/08/25 12:37:18 Cause: glBeginConditionalRender 2019/08/25 12:37:18 At: C:/Users/ABCD/go/src/fyne.io/fyne/internal/driver/gl/window.go:1007 panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x2c pc=0x572afd] goroutine 1 [running, locked to thread]: fyne.io/fyne/internal/driver/gl.(*window).SetContent(0x0, 0x8fc5e0, 0x1386e0c0) C:/Users/ABCD/go/src/fyne.io/fyne/internal/driver/gl/window.go:361 +0x1d main.main() I:/rnfynetest.go:10 +0x1ce </code></pre> <p>As given on <a href="https://github.com/fyne-io/fyne" rel="nofollow noreferrer">Fyne homepage</a> I need to install OpenGL. From <a href="https://github.com/go-gl/gl" rel="nofollow noreferrer">go bindings for OpenGL</a> it seems there are three ways to install it:</p> <pre><code>go get -u github.com/go-gl/gl/v{3.2,3.3,4.1,4.2,4.3,4.4,4.5,4.6}-{core,compatibility}/gl go get -u github.com/go-gl/gl/v3.1/gles2 go get -u github.com/go-gl/gl/v2.1/gl </code></pre> <p>Which of these commands do I need to use? I am working on <code>Windows7</code> and using <code>go version go1.12.9 windows/386</code></p> <p>Thanks for your help.</p> <p><strong><em>Edit:</em></strong> </p> <p>I tried following commands:</p> <pre><code>go get -u github.com/go-gl/gl/v2.1/gl go get -u github.com/go-gl/gl/v4.6-core/gl go get -u github.com/go-gl/gl/v4.6-compatibility/gl </code></pre> <p>They all install all right but same error is persisting on trying to run built executable. </p> <p>I also tried gles2 but it does not install rather gives following error:</p> <pre><code>I:\&gt;go get -u github.com/go-gl/gl/v3.1/gles2 # github.com/go-gl/gl/v3.1/gles2 C:\Users\ABCD\go\src\github.com\go-gl\gl\v3.1\gles2\package.go:38:11: fatal error: KHR/khrplatform.h: No such file or directory // #include &lt;KHR/khrplatform.h&gt; ^~~~~~~~~~~~~~~~~~~ compilation terminated. </code></pre> </div>

Golang OpenGL错误PlatformError:X11:DISPLAY环境变量缺少紧急信息:NotInitialized:GLFW库未初始化

<div class="post-text" itemprop="text"> <p>I just cannot seem to get opengl with golang to work. I wanted to try out golang but it has been such a pain to even set up, and now I can't get something I copy pasted off of <a href="https://kylewbanks.com/blog/tutorial-opengl-with-golang-part-1-hello-opengl" rel="nofollow noreferrer">this website</a>. Here is the code I am using: <a href="https://pastebin.com/Wzwdc586" rel="nofollow noreferrer">(from the website)</a>. I did these two commands before running it (using wsl on windows):</p> <pre><code>go get github.com/go-gl/gl/v4.1-core/gl go get github.com/go-gl/glfw/v3.2/glfw </code></pre> <p>And this is the full error I am getting:</p> <pre><code>2018/11/21 13:43:33 PlatformError: X11: The DISPLAY environment variable is missing panic: NotInitialized: The GLFW library is not initialized goroutine 1 [running, locked to thread]: github.com/go-gl/glfw/v3.2/glfw.acceptError(0x0, 0x0, 0x0, 0x1, 0xc000099ee0) /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:173 +0x1d1 github.com/go-gl/glfw/v3.2/glfw.panicError() /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:184 +0x32 github.com/go-gl/glfw/v3.2/glfw.WindowHint(0x20003, 0x0) /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/window.go:235 +0x38 main.initGlfw(0x4ded35) /home/oriont/dev/super g/main.go:71 +0x54 main.main() /home/oriont/dev/super g/main.go:45 +0x2b exit status 2 </code></pre> <p>And if you are curious, my go env:</p> <pre><code>GOARCH="amd64" GOBIN="" GOCACHE="/home/oriont/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/oriont/dev" GOPROXY="" GORACE="" GOROOT="/usr/lib/go-1.11" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.11/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build854283259=/tmp/go-build -gno-record-gcc-switches" </code></pre> <p>Any help would be appreciated, thanks!</p> <p>EDIT:</p> <p>Now I am getting a new error, after reinstalling go and removing a failed attempt at sdl2 (from apt-get remove).</p> <p>(OLD) This is the new error:</p> <pre><code># _/home/oriont/dev/super_g /usr/lib/go-1.11/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: cannot find -lXrandr collect2: error: ld returned 1 exit status </code></pre> <p>I have all of the same code still. Also, I did try to run 'go build' but it just threw the exact same error as 'go run main.go'.</p> <p>EDIT 2:</p> <p>I reinstalled go 1.11.2 and installed the libglfw3 and libglfw3-dev packages on sudo apt-get install. Now, I have the same old error.</p> </div>

OpenGL二维绘图:大佬们,GL如何实现将点阵图像放大并自动平滑显示?

想做出类似Direct2D的DrawBitmap、Qt的DrawImage的效果(如下图) ![图片说明](https://img-ask.csdn.net/upload/201904/11/1554950468_577785.jpg) 已试 ``` glPixelZoom((GLfloat)xscale, (GLfloat)yscale); glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, Buffer); ``` 感觉绘图效率有点低,而且暂时没找到平滑的方法,求助有没有其他的解决方法?

OpenGL中的图片打不开

我在学习NeHe教程,用的是vs2010,纹理时加载不进去,调试时这段代码直接就跳过了,文件加载不进去 if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } 各位大神求解答 /* * This Code Was Created By Jeff Molofee 2000 * A HUGE Thanks To Fredric Echols For Cleaning Up * And Optimizing The Base Code, Making It More Flexible! * If You've Found This Code Useful, Please Let Me Know. * Visit My Site At nehe.gamedev.net */ #define _CRT_SECURE_NO_WARNINGS #include <windows.h> // Header File For Windows #include <stdio.h> // Header File For Standard Input/Output #include <gl\gl.h> // Header File For The OpenGL32 Library #include <gl\glu.h> // Header File For The GLu32 Library #include <gl\glaux.h> // Header File For The Glaux Library HDC hDC=NULL; // Private GDI Device Context HGLRC hRC=NULL; // Permanent Rendering Context HWND hWnd=NULL; // Holds Our Window Handle HINSTANCE hInstance; // Holds The Instance Of The Application bool keys[256]; // Array Used For The Keyboard Routine bool active=TRUE; // Window Active Flag Set To TRUE By Default bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default bool texLoaded = false; GLfloat xrot; // X Rotation ( NEW ) GLfloat yrot; // Y Rotation ( NEW ) GLfloat zrot; // Z Rotation ( NEW ) GLuint texture[1]; // Storage For One Texture ( NEW ) LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL } File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL } int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("Data\NeHe.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } return Status; // Return The Status } GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window { if (height==0) // Prevent A Divide By Zero By { height=1; // Making Height Equal One } glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix } int InitGL(GLvoid) // All Setup For OpenGL Goes Here { if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW ) { return FALSE; // If Texture Didn't Load Return FALSE } glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations return TRUE; // Initialization Went OK } int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0f,0.0f,-5.0f); glRotatef(xrot,1.0f,0.0f,0.0f); glRotatef(yrot,0.0f,1.0f,0.0f); glRotatef(zrot,0.0f,0.0f,1.0f); glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); xrot+=0.3f; yrot+=0.2f; zrot+=0.4f; return TRUE; // Keep Going } GLvoid KillGLWindow(GLvoid) // Properly Kill The Window { if (fullscreen) // Are We In Fullscreen Mode? { ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop ShowCursor(TRUE); // Show Mouse Pointer } if (hRC) // Do We Have A Rendering Context? { if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts? { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC? { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; // Set RC To NULL } if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; // Set DC To NULL } if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window? { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; // Set hWnd To NULL } if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; // Set hInstance To NULL } } /* This Code Creates Our OpenGL Window. Parameters Are: * * title - Title To Appear At The Top Of The Window * * width - Width Of The GL Window Or Fullscreen Mode * * height - Height Of The GL Window Or Fullscreen Mode * * bits - Number Of Bits To Use For Color (8/16/24/32) * * fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; // Holds The Results After Searching For A Match WNDCLASS wc; // Windows Class Structure DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values WindowRect.left=(long)0; // Set Left Value To 0 WindowRect.right=(long)width; // Set Right Value To Requested Width WindowRect.top=(long)0; // Set Top Value To 0 WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height fullscreen=fullscreenflag; // Set The Global Fullscreen Flag hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName ="OpenGL"; // Set The Class Name if (!RegisterClass(&wc)) // Attempt To Register The Window Class { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (fullscreen) // Attempt Fullscreen Mode? { DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure dmScreenSettings.dmPelsWidth = width; // Selected Screen Width dmScreenSettings.dmPelsHeight = height; // Selected Screen Height dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE } else { // Pop Up A Message Box Letting User Know The Program Is Closing. MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP); return FALSE; // Return FALSE } } } if (fullscreen) // Are We Still In Fullscreen Mode? { dwExStyle=WS_EX_APPWINDOW; // Window Extended Style dwStyle=WS_POPUP; // Windows Style ShowCursor(FALSE); // Hide Mouse Pointer } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // Create The Window if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window "OpenGL", // Class Name title, // Window Title dwStyle | // Defined Window Style WS_CLIPSIBLINGS | // Required Window Style WS_CLIPCHILDREN, // Required Window Style 0, 0, // Window Position WindowRect.right-WindowRect.left, // Calculate Window Width WindowRect.bottom-WindowRect.top, // Calculate Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL))) // Dont Pass Anything To WM_CREATE { KillGLWindow(); // Reset The Display MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format bits, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } ShowWindow(hWnd,SW_SHOW); // Show The Window SetForegroundWindow(hWnd); // Slightly Higher Priority SetFocus(hWnd); // Sets Keyboard Focus To The Window ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen if (!InitGL()) // Initialize Our Newly Created GL Window { KillGLWindow(); // Reset The Display MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } return TRUE; // Success } LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { switch (uMsg) // Check For Windows Messages { case WM_ACTIVATE: // Watch For Window Activate Message { if (!HIWORD(wParam)) // Check Minimization State { active=TRUE; // Program Is Active } else { active=FALSE; // Program Is No Longer Active } return 0; // Return To The Message Loop } case WM_SYSCOMMAND: // Intercept System Commands { switch (wParam) // Check System Calls { case SC_SCREENSAVE: // Screensaver Trying To Start? case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? return 0; // Prevent From Happening } break; // Exit } case WM_CLOSE: // Did We Receive A Close Message? { PostQuitMessage(0); // Send A Quit Message return 0; // Jump Back } case WM_KEYDOWN: // Is A Key Being Held Down? { keys[wParam] = TRUE; // If So, Mark It As TRUE return 0; // Jump Back } case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = FALSE; // If So, Mark It As FALSE return 0; // Jump Back } case WM_SIZE: // Resize The OpenGL Window { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure BOOL done=FALSE; // Bool Variable To Exit Loop // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow("NeHe's Texture Mapping Tutorial",640,480,16,fullscreen)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=TRUE; // If So done=TRUE } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received? { done=TRUE; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { SwapBuffers(hDC); // Swap Buffers (Double Buffering) } if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1]=FALSE; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow("NeHe's Texture Mapping Tutorial",640,480,16,fullscreen)) { return 0; // Quit If Window Was Not Created } } } } // Shutdown KillGLWindow(); // Kill The Window return (msg.wParam); // Exit The Program }

用opengl采用中点生成算法画出y=x∧3,x属于0到10

用opengl采用中点生成算法画出曲线y=x∧3,x属于0到10,求代码!

用VS2013编译opengl编程宝典第五版的第一个画三角形的例子,编译后程序运行不了

![![![图片说明](https://img-ask.csdn.net/upload/201602/05/1454665400_904503.png)图片说明](https://img-ask.csdn.net/upload/201602/05/1454665388_987111.png)图片说明](https://img-ask.csdn.net/upload/201602/05/1454665377_645669.png) 代码如下: #include<Gltools.h> #include<GLShadermanager.h> #define FERRGLUT_STATIC #include<gl/glut.h> #include<gl/glew.h> GLBatch trianglebatch; GLShaderManager shadermanager; int main(int argc, char* argv[]) { void RenderScene(); void ChangeSize(int w, int h); void SetupRC(); gltSetWorkingDirectory(argv[0]); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(800, 600); glutCreateWindow("triangle"); glutReshapeFunc(ChangeSize); glutDisplayFunc(RenderScene); GLenum err = glewInit(); if (GLEW_OK != err){ fprintf(stderr, "GLEW Error:%s\n", glewGetErrorString(err)); return 1; } SetupRC(); glutMainLoop(); return 0; } void ChangeSize(int w, int h) { glViewport(0, 0, w, h); } void SetupRC() { glClearColor(0.0f, 0.0f, 1.0f, 1.0f); shadermanager.InitializeStockShaders(); GLfloat vVerts[9] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; trianglebatch.Begin(GL_TRIANGLES, 3); trianglebatch.CopyVertexData3f(vVerts); trianglebatch.End(); } void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[3] = { 1.0f, 0.0f, 0.0f }; shadermanager.UseStockShader(GLT_SHADER_IDENTITY, vRed); trianglebatch.Draw(); glutSwapBuffers(); } 网上看说有“0xC0000005: 写入位置 0x000000AC 时发生访问冲突”这种问题是指针没有赋值,可是我是按照例子敲的代码啊。求大神解答。

VS2010Debug编译exe运行报错0xc000007b?

Release32位编译exe运行正常,Debug就不行,就只写一行简单的puts也是这样的问题。 ![图片说明](https://img-ask.csdn.net/upload/201903/29/1553841941_187182.jpg) 网上说的安装DirectX 9.0c这个解决不了,其它的说法缺少dll库的肯定都不是。

怎么解决opengl使用C++文件流读取着色器内容时发生错误的问题?

![图片说明](https://img-ask.csdn.net/upload/201904/18/1555600254_301885.png) ``` //main.cpp #include <glad/glad.h> #include <GLFW/glfw3.h> #include "filesystem.h" #include "shader.h" #define STB_IMAGE_IMPLEMENTATION #include <stb_image.h> #include <iostream> void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); // settings const unsigned int SCR_WIDTH = 600; const unsigned int SCR_HEIGHT = 600; float mixValue = 0.2f; int main() { // glfw: initialize and configure // ------------------------------ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X #endif // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers // --------------------------------------- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } // build and compile our shader zprogram // ------------------------------------ Shader ourShader("4.1.texture.vs", "4.1.texture.fs"); // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ float vertices[] = { // positions // colors // texture coords 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top left }; unsigned int indices[] = { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; unsigned int VBO, VAO, EBO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); // position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // color attribute glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); // 解析纹理坐标数据,请补充完整 //texture coord attribute glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); glEnableVertexAttribArray(2); stbi_set_flip_vertically_on_load(true); //创建纹理过程,请补充完整 // load and create a texture // ------------------------- unsigned int texture1,texture2; glGenTextures(1, &texture1); glBindTexture(GL_TEXTURE_2D, texture1); // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // set texture filtering parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The FileSystem::getPath(...) is part of the GitHub repository so we can find files on any IDE/platform; replace it with your own image path. int width, height, nrChannels; unsigned char *data = stbi_load("D:/LearnOpenGL-master/LearnOpenGL-master/resources/textures/container.jpg", &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); } else { std::cout << "Failed to load texture1" << std::endl; } glGenTextures(1, &texture2); glBindTexture(GL_TEXTURE_2D, texture2); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); data = stbi_load("D:/LearnOpenGL-master/LearnOpenGL-master/resources/textures/awesomeface.png", &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); } else { std::cout << "Failed to load texture2" << std::endl; } ourShader.use(); glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0); ourShader.setInt("texture2", 1); // render loop // ----------- while (!glfwWindowShouldClose(window)) { // input // ----- processInput(window); // render // ------ glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // bind Texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture1); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture2); // set the texture mix value in the shader ourShader.setFloat("mixValue", mixValue); // render container ourShader.use(); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // ------------------------------------------------------------------------------- glfwSwapBuffers(window); glfwPollEvents(); } // optional: de-allocate all resources once they've outlived their purpose: // ------------------------------------------------------------------------ glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &EBO); // glfw: terminate, clearing all previously allocated GLFW resources. // ------------------------------------------------------------------ glfwTerminate(); return 0; } // process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly // --------------------------------------------------------------------------------------------------------- void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) { mixValue += 0.001f; // change this value accordingly (might be too slow or too fast based on system hardware) if (mixValue >= 1.0f) mixValue = 1.0f; } if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) { mixValue -= 0.001f; // change this value accordingly (might be too slow or too fast based on system hardware) if (mixValue <= 0.0f) mixValue = 0.0f; } } // glfw: whenever the window size changed (by OS or user resize) this callback function executes // --------------------------------------------------------------------------------------------- void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } //shader_s.h #ifndef SHADER_H #define SHADER_H #include <glad/glad.h> #include <string> #include <fstream> #include <sstream> #include <iostream> class Shader { public: unsigned int ID; // constructor generates the shader on the fly // ------------------------------------------------------------------------ Shader(const char* vertexPath, const char* fragmentPath) { // 1. retrieve the vertex/fragment source code from filePath std::string vertexCode; std::string fragmentCode; std::ifstream vShaderFile; std::ifstream fShaderFile; // ensure ifstream objects can throw exceptions: vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); try { // open files vShaderFile.open(vertexPath); fShaderFile.open(fragmentPath); std::stringstream vShaderStream, fShaderStream; // read file's buffer contents into streams vShaderStream << vShaderFile.rdbuf(); fShaderStream << fShaderFile.rdbuf(); // close file handlers vShaderFile.close(); fShaderFile.close(); // convert stream into string vertexCode = vShaderStream.str(); fragmentCode = fShaderStream.str(); } catch (std::ifstream::failure e) { std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl; } const char* vShaderCode = vertexCode.c_str(); const char * fShaderCode = fragmentCode.c_str(); // 2. compile shaders unsigned int vertex, fragment; // vertex shader vertex = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertex, 1, &vShaderCode, NULL); glCompileShader(vertex); checkCompileErrors(vertex, "VERTEX"); // fragment Shader fragment = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment, 1, &fShaderCode, NULL); glCompileShader(fragment); checkCompileErrors(fragment, "FRAGMENT"); // shader Program ID = glCreateProgram(); glAttachShader(ID, vertex); glAttachShader(ID, fragment); glLinkProgram(ID); checkCompileErrors(ID, "PROGRAM"); // delete the shaders as they're linked into our program now and no longer necessary glDeleteShader(vertex); glDeleteShader(fragment); } // activate the shader // ------------------------------------------------------------------------ void use() { glUseProgram(ID); } // utility uniform functions // ------------------------------------------------------------------------ void setBool(const std::string &name, bool value) const { glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value); } // ------------------------------------------------------------------------ void setInt(const std::string &name, int value) const { glUniform1i(glGetUniformLocation(ID, name.c_str()), value); } // ------------------------------------------------------------------------ void setFloat(const std::string &name, float value) const { glUniform1f(glGetUniformLocation(ID, name.c_str()), value); } private: // utility function for checking shader compilation/linking errors. // ------------------------------------------------------------------------ void checkCompileErrors(unsigned int shader, std::string type) { int success; char infoLog[1024]; if (type != "PROGRAM") { glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(shader, 1024, NULL, infoLog); std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl; } } else { glGetProgramiv(shader, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shader, 1024, NULL, infoLog); std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl; } } } }; #endif

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐