@@ -155,7 +155,6 @@ typedef struct {
155155static CellProgramLayout cell_program_layouts [NUM_PROGRAMS ];
156156static GLuint offscreen_framebuffer = 0 ;
157157static GLuint scroll_framebuffer = 0 ;
158- static unsigned int scroll_texture = 0 ;
159158static unsigned int quadVAO , quadVBO ;
160159static ssize_t blit_vertex_array ;
161160
@@ -179,18 +178,18 @@ init_cell_program(void) {
179178 blit_vertex_array = create_vao ();
180179}
181180
182- void setup_scroll (int UNUSED width , int UNUSED height ) {
181+ void setup_scroll (OSWindow * os_window ) {
183182 glGenFramebuffers (1 , & scroll_framebuffer );
184183 glBindFramebuffer (GL_FRAMEBUFFER , scroll_framebuffer );
185- glGenTextures (1 , & scroll_texture );
186- glBindTexture (GL_TEXTURE_2D , scroll_texture );
187- printf ("%d %d\n" , width , height );
188- glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGB , width , height , 0 , GL_RGB , GL_UNSIGNED_BYTE , NULL );
189- //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB , 640, 400, 0, GL_RGB , GL_UNSIGNED_BYTE, NULL);
184+ glGenTextures (1 , & os_window -> scroll_texture_id );
185+ glBindTexture (GL_TEXTURE_2D , os_window -> scroll_texture_id );
186+ printf ("%d %d\n" , os_window -> viewport_width , os_window -> viewport_height );
187+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , os_window -> viewport_width , os_window -> viewport_height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NULL );
188+ //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA , 640, 400, 0, GL_RGBA , GL_UNSIGNED_BYTE, NULL);
190189 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR );
191190 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR );
192191 glBindTexture (GL_TEXTURE_2D , 0 );
193- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , scroll_texture , 0 );
192+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , os_window -> scroll_texture_id , 0 );
194193
195194 float quadVertices [] = { // vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.
196195 // positions // texCoords
@@ -221,7 +220,7 @@ void before_render() {
221220 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // we're not using the stencil buffer now
222221}
223222
224- void after_render (double pixels ) {
223+ void after_render (OSWindow * os_window , double pixels ) {
225224 // second pass
226225 glBindFramebuffer (GL_FRAMEBUFFER , 0 ); // back to default
227226 glClearColor (0.5f , 0.5f , 0.5f , 1.0f );
@@ -231,7 +230,7 @@ void after_render(double pixels) {
231230 bind_program (SCROLL_PROGRAM );
232231 glUniform1f (glGetUniformLocation (program_id (SCROLL_PROGRAM ), "offset" ), pixels );
233232 glBindVertexArray (quadVAO );
234- glBindTexture (GL_TEXTURE_2D , scroll_texture );
233+ glBindTexture (GL_TEXTURE_2D , os_window -> scroll_texture_id );
235234 glDrawArrays (GL_TRIANGLES , 0 , 6 );
236235}
237236
0 commit comments