flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > can someone provide a simple opengl shader tutorial Goto page 1, 2 Next |
Author |
|
mikokawasaki 28 May 2013, 10:56
(*noob) can someone provide a simple opengl shader tutorial
|
|||
28 May 2013, 10:56 |
|
edfed 28 May 2013, 15:12
|
|||
28 May 2013, 15:12 |
|
HaHaAnonymous 28 May 2013, 20:22
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 20:17; edited 1 time in total |
|||
28 May 2013, 20:22 |
|
bitRAKE 28 May 2013, 20:55
HaHaAnonymous wrote:
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
28 May 2013, 20:55 |
|
HaHaAnonymous 28 May 2013, 21:40
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 20:17; edited 1 time in total |
|||
28 May 2013, 21:40 |
|
mikokawasaki 29 May 2013, 12:23
bitRAKE why do you feel so offended by openGL...
i dont care if its taught in schools or not.. i came here for help, not for someone to tell me to get lost... im only new to assembley... i understand a little bit though.. i cant get access to functions like glcreateshader for my project thats why im asking for help.. |
|||
29 May 2013, 12:23 |
|
bitRAKE 29 May 2013, 23:55
I suggest to search for GLSL and demo scene. All the other bits you assume yourself. No offense is meant to anyone.
|
|||
29 May 2013, 23:55 |
|
randall 30 May 2013, 10:32
Here is my Mandelbrot OpenGL renderer on Linux:
http://board.flatassembler.net/topic.php?t=14100 I am not using GLSL but NVIDIA assembly shaders. Maybe it will be helpful. |
|||
30 May 2013, 10:32 |
|
mikokawasaki 02 Jun 2013, 12:57
the code is really long so i'll give you the highlight of my problem....
this code runs fine but the shader part is not working... format PE64 GUI 5.0 entry start include 'compiler\include\win64ax.inc' include 'compiler\include\opengl.inc' ==================================== invoke wglGetProcAddress,"glCreateShader" mov [glCreateShader],rax invoke wglGetProcAddress,"glCreateProgram" mov [glCreateProgram],rax invoke wglGetProcAddress,"glShaderSource" mov [glShaderSource],rax invoke wglGetProcAddress,"glCompileShader" mov [glCompileShader],rax invoke wglGetProcAddress,"glAttachShader" mov [glAttachShader],rax invoke wglGetProcAddress,"glLinkProgram" mov [glLinkProgram],rax invoke wglGetProcAddress,"glUseProgram" mov [glUseProgram],rax invoke glCreateShader, GL_FRAGMENT_SHADER mov [vs],rax invoke glCreateProgram mov [prg],rax invoke glShaderSource,vs,1,[_fshader],0 invoke glCompileShader,vs invoke glAttachShader,prg,vs invoke glLinkProgram,prg invoke glUseProgram,prg ================================ ;glGenBuffers dq ? ;glCreateShader dq ? ;glCreateProgram dq ? ;glShaderSource dq ? ;glCompileShader dq ? ;glAttachShader dq ? ;glLinkProgram dq ? ;glUseProgram dq ? ;vs dq ? ;prg dq ? _fshader db 'void main(){ gl_FragColor = vec4(0.0,0.0,1.0,1.0); } ',0 |
|||
02 Jun 2013, 12:57 |
|
tthsqe 02 Jun 2013, 23:07
If you get something working in windows please post it here.
|
|||
02 Jun 2013, 23:07 |
|
typedef 03 Jun 2013, 04:11
bitRAKE wrote: I suggest to search for GLSL and demo scene. All the other bits you assume yourself. No offense is meant to anyone. Hey aren't you the one that made an FPS world in Assembly using OpenGL ? I remember sometime back someone made one. |
|||
03 Jun 2013, 04:11 |
|
tthsqe 03 Jun 2013, 04:41
Yes, he was, but that didn't make use of custom shaders. I'm sure that it was textures with the ordinary opengl pipeline.
|
|||
03 Jun 2013, 04:41 |
|
bitRAKE 03 Jun 2013, 06:45
Nah, you are probably thinking about r22,
http://board.flatassembler.net/topic.php?t=8381 I read a book about OpenGL back in the 1.0 days, but have never coded anything using it. If someone would have listened to me and bought Pixar stock back then... _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
03 Jun 2013, 06:45 |
|
dancho 03 Jun 2013, 08:05
modern opengl 3.3 ver using vertex and fragment shader in C ,
but you will get idea behind it... using : 1.) glfw opengl framework http://www.glfw.org/ 2.) glew extension http://glew.sourceforge.net/ main.c Code: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <GL/glew.h> #include <GL/glfw.h> #include "load_shaders.h" static const float gVertexBufferData[] = { -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 0.0f, 1.0f,0.0f }; int main(int argc,char **argv) { if(glfwInit()==GL_FALSE) { fprintf(stderr,"Failed to initialze GLFW"); return -1; } glfwOpenWindowHint(GLFW_FSAA_SAMPLES,4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR,3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR,3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); if(glfwOpenWindow(800,600,0,0,0,0,32,0,GLFW_WINDOW)==GL_FALSE) { fprintf(stderr,"Failed to open GLFW window"); glfwTerminate(); return -1; } glewExperimental = true; if(glewInit()!=GLEW_OK) { fprintf(stderr,"Failed to initialize Glew"); glfwTerminate(); return -1; } glfwSetWindowTitle("Simple Shader"); glfwEnable(GLFW_STICKY_KEYS); glClearColor(0.0f,0.0f,0.4f,0.0f); // create vertex array object GLuint vertexArrayObj; glGenVertexArrays(1,&vertexArrayObj); glBindVertexArray(vertexArrayObj); // create vertex buffer object GLuint vertexBufferObj; glGenBuffers(1,&vertexBufferObj); glBindBuffer(GL_ARRAY_BUFFER,vertexBufferObj); glBufferData(GL_ARRAY_BUFFER,sizeof(gVertexBufferData),gVertexBufferData,GL_STATIC_DRAW); GLuint programID; if((programID=LoadShaders("SimpleVertexShader.vertexshader","SimpleFragmentShader.fragmentshader"))==0) { fprintf(stderr,"Error at LoadShader func"); return -1; } do { glClear(GL_COLOR_BUFFER_BIT); glUseProgram(programID); glEnableVertexAttribArray(0); glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0); glDrawArrays(GL_TRIANGLES,0,3); glDisableVertexAttribArray(0); glfwSwapBuffers(); } while(glfwGetKey(GLFW_KEY_ESC)!=GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED)); glfwTerminate(); glDeleteBuffers(1,&vertexBufferObj); glDeleteVertexArrays(1,&vertexArrayObj); return 0; } load_shaders.h Code: #ifndef LOADSHADERS #define LOADSHADERS extern GLuint LoadShaders(const char *vertexShaderFile,const char *fragmentShaderFile); #endif load_shaders.c Code: #include <stdio.h> #include <stdlib.h> #include <GL/glew.h> #include <GL/glfw.h> #include "load_shaders.h" static char * ReadShaderFile(const char *fileName) { FILE *shaderStream = NULL; if((shaderStream = fopen(fileName,"r"))==NULL) { fprintf(stderr,"Can't open shader file"); return NULL; } long int pos = ftell(shaderStream); fseek(shaderStream,pos,SEEK_END); long int len = ftell(shaderStream); fseek(shaderStream,pos,SEEK_SET); char *shaderCode = NULL; if((shaderCode = malloc(len*sizeof(char)))==NULL) { fprintf(stderr,"Can't allocate memory for the shader code"); fclose(shaderStream); return NULL; } unsigned int i = 0; char c; while((c = (char)fgetc(shaderStream))!=EOF) { shaderCode[i] = c; i++; } shaderCode[i] = 0; fclose(shaderStream); return shaderCode; } GLuint LoadShaders(const char *vertexShaderFile,const char *fragmentShaderFile) { // read vertex shader char *vertexShaderCode = NULL; if((vertexShaderCode = (ReadShaderFile(vertexShaderFile)))==NULL) { fprintf(stderr,"Can't read vertex shader file"); return 0; } // read fragment shader char *fragmentShaderCode = NULL; if((fragmentShaderCode = (ReadShaderFile(fragmentShaderFile)))==NULL) { fprintf(stderr,"Can't read fragment shader file"); return 0; } char const *vertexPtr = vertexShaderCode; // compile vertex shader printf("Compiling shader : %s\n",vertexShaderFile); GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShaderID,1,&vertexPtr,NULL); glCompileShader(vertexShaderID); GLint result = GL_FALSE; // check vertex shader glGetShaderiv(vertexShaderID,GL_COMPILE_STATUS,&result); if(result==GL_FALSE) { fprintf(stderr,"Error compiling vertex shader\n"); free(vertexShaderCode); return 0; } char const *fragmentPtr = fragmentShaderCode; // compile fragment shader printf("Compiling shader : %s\n",fragmentShaderFile); GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShaderID,1,&fragmentPtr,NULL); glCompileShader(fragmentShaderID); // check fragment shader glGetShaderiv(fragmentShaderID,GL_COMPILE_STATUS,&result); if(result==GL_FALSE) { fprintf(stderr,"Error compiling fragment shader\n"); free(fragmentShaderCode); return 0; } // linking program printf("Linking program\n"); GLuint programID = glCreateProgram(); glAttachShader(programID,vertexShaderID); glAttachShader(programID,fragmentShaderID); glLinkProgram(programID); // check program glGetProgramiv(programID,GL_LINK_STATUS,&result); if(result==GL_FALSE) { fprintf(stderr,"Error linkinig shaders\n"); free(vertexShaderCode); free(fragmentShaderCode); glDeleteShader(vertexShaderID); glDeleteShader(fragmentShaderID); return 0; } free(vertexShaderCode); free(fragmentShaderCode); glDeleteShader(vertexShaderID); glDeleteShader(fragmentShaderID); return programID; } SimpleVertexShader.vertexshader Code: #version 330 core // Input vertex data layout(location = 0) in vec3 vertexPosition_modelspace; void main(){ gl_Position.xyz = vertexPosition_modelspace; gl_Position.w = 1.0; } SimpleFragmentShader.fragmentshader Code: #version 330 core // Ouput data out vec3 color; void main() { // Output color = red color = vec3(1,0,0); } |
|||
03 Jun 2013, 08:05 |
|
mikokawasaki 04 Jun 2013, 03:39
tthsqe, ill definitally post it if i can get it to work...
im guessing its the _fshader declaration type part idk... |
|||
04 Jun 2013, 03:39 |
|
randall 04 Jun 2013, 07:37
Third parameter to glShaderSource is a pointer to pointer so in fasm in 64bits it must be like this:
align 1 shader_source db '<shader source>',0 align 8 shader_source_ptr dq shader_source invoke glShaderSource,vs,1,shader_source_ptr,0 |
|||
04 Jun 2013, 07:37 |
|
mikokawasaki 04 Jun 2013, 10:08
[ Post removed by author. ]
Last edited by mikokawasaki on 04 Jun 2013, 10:46; edited 4 times in total |
|||
04 Jun 2013, 10:08 |
|
randall 04 Jun 2013, 10:29
I don't know invoke macro but all these :
Code: invoke glCompileShader,vs invoke glAttachShader,prg,vs invoke glLinkProgram,prg invoke glUseProgram,prg Should be: Code: invoke glCompileShader,[vs] invoke glAttachShader,[prg],[vs] invoke glLinkProgram,[prg] invoke glUseProgram,[prg] OpenGL returns integer values that are handles to the resources. |
|||
04 Jun 2013, 10:29 |
|
mikokawasaki 04 Jun 2013, 10:47
I got it working now....
im posting for anyone interested... thank you randall for "pointing" that out... i learned something new... heres the working shader code thing im using... Code: invoke wglGetProcAddress,"glCreateShader" mov [glCreateShader],rax invoke wglGetProcAddress,"glCreateProgram" mov [glCreateProgram],rax invoke wglGetProcAddress,"glShaderSource" mov [glShaderSource],rax invoke wglGetProcAddress,"glCompileShader" mov [glCompileShader],rax invoke wglGetProcAddress,"glAttachShader" mov [glAttachShader],rax invoke wglGetProcAddress,"glLinkProgram" mov [glLinkProgram],rax invoke wglGetProcAddress,"glUseProgram" mov [glUseProgram],rax invoke glCreateShader, GL_FRAGMENT_SHADER mov [vs],rax invoke glCreateProgram mov [prg],rax invoke glShaderSource,[vs],1,_fshader_ptr,0 invoke glCompileShader,[vs] invoke glAttachShader,[prg],[vs] invoke glLinkProgram,[prg] invoke glUseProgram,[prg] ... glGenBuffers dq ? glCreateShader dq ? glCreateProgram dq ? glShaderSource dq ? glCompileShader dq ? glAttachShader dq ? glLinkProgram dq ? glUseProgram dq ? vs dq ? prg dq ? align 1 _fshader db 'void main(){ gl_FragColor = vec4(0.0,0.0,1.0,1.0); } ',0 align 8 _fshader_ptr dq _fshader |
|||
04 Jun 2013, 10:47 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.